Skip to content

Commit 71562b2

Browse files
committed
P2447R6 std::span over an initializer list
1 parent ecbeb5a commit 71562b2

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

source/compatibility.tex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@
6464
// changed according to the global C locale
6565
\end{codeblock}
6666

67+
\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}
68+
69+
\diffref{span.overview}
70+
\change
71+
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
72+
\rationale
73+
Permit passing a braced initializer list to a function taking \tcode{span}.
74+
\effect
75+
Valid \CppXXIII{} code that relies on the lack of this constructor
76+
may refuse to compile, or change behavior in this revision of \Cpp{}.
77+
For example:
78+
\begin{codeblock}
79+
void one(pair<int, int>); // \#1
80+
void one(span<const int>); // \#2
81+
void t1() { one({1,2}); } // ambiguous between \#1 and \#2; previously called \#1
82+
83+
void two(span<const int, 2>);
84+
void t2() { two({{1,2}}); } // ill-formed; previously well-formed
85+
86+
void *a[10];
87+
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
88+
any b[10];
89+
int y = span<const any>{b, b+10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
90+
\end{codeblock}
91+
6792
\rSec1[diff.cpp20]{\Cpp{} and ISO \CppXX{}}
6893

6994
\rSec2[diff.cpp20.general]{General}

source/containers.tex

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18218,6 +18218,8 @@
1821818218

1821918219
\indexheader{span}%
1822018220
\begin{codeblock}
18221+
#include <initializer_list> // see \ref{initializer.list.syn}
18222+
1822118223
namespace std {
1822218224
// constants
1822318225
inline constexpr size_t @\libglobal{dynamic_extent}@ = numeric_limits<size_t>::max();
@@ -18289,6 +18291,7 @@
1828918291
constexpr span(const array<T, N>& arr) noexcept;
1829018292
template<class R>
1829118293
constexpr explicit(extent != dynamic_extent) span(R&& r);
18294+
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
1829218295
constexpr span(const span& other) noexcept = default;
1829318296
template<class OtherElementType, size_t OtherExtent>
1829418297
constexpr explicit(@\seebelow@) span(const span<OtherElementType, OtherExtent>& s) noexcept;
@@ -18533,6 +18536,27 @@
1853318536
What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw.
1853418537
\end{itemdescr}
1853518538

18539+
\indexlibraryctor{span}%
18540+
\begin{itemdecl}
18541+
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
18542+
\end{itemdecl}
18543+
18544+
\begin{itemdescr}
18545+
\pnum
18546+
\constraints
18547+
\tcode{is_const_v<element_type>} is \tcode{true}.
18548+
18549+
\pnum
18550+
\expects
18551+
If \tcode{extent} is not equal to \tcode{dynamic_extent}, then
18552+
\tcode{il.size()} is equal to \tcode{extent}.
18553+
18554+
\pnum
18555+
\effects
18556+
Initializes \exposid{data_} with \tcode{il.begin()} and
18557+
\exposid{size_} with \tcode{il.size()}.
18558+
\end{itemdescr}
18559+
1853618560
\indexlibraryctor{span}%
1853718561
\begin{itemdecl}
1853818562
constexpr span(const span& other) noexcept = default;

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@
753753
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
754754
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}
755755
#define @\defnlibxname{cpp_lib_span}@ 202002L // also in \libheader{span}
756+
#define @\defnlibxname{cpp_lib_span_initializer_list}@ 202311L // also in \libheader{span}
756757
#define @\defnlibxname{cpp_lib_spanstream}@ 202106L // also in \libheader{spanstream}
757758
#define @\defnlibxname{cpp_lib_ssize}@ 201902L // freestanding, also in \libheader{iterator}
758759
#define @\defnlibxname{cpp_lib_sstream_from_string_view}@ 202306L // also in \libheader{sstream}

0 commit comments

Comments
 (0)