Skip to content

Commit b973d5e

Browse files
authored
Merge 2023-11 LWG Motion 9
P2447R6 std::span over an initializer list
2 parents 8639700 + d5ef937 commit b973d5e

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
@@ -107,6 +107,31 @@
107107
// changed according to the global C locale
108108
\end{codeblock}
109109

110+
\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}
111+
112+
\diffref{span.overview}
113+
\change
114+
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
115+
\rationale
116+
Permit passing a braced initializer list to a function taking \tcode{span}.
117+
\effect
118+
Valid \CppXXIII{} code that relies on the lack of this constructor
119+
may refuse to compile, or change behavior in this revision of \Cpp{}.
120+
For example:
121+
\begin{codeblock}
122+
void one(pair<int, int>); // \#1
123+
void one(span<const int>); // \#2
124+
void t1() { one({1, 2}); } // ambiguous between \#1 and \#2; previously called \#1
125+
126+
void two(span<const int, 2>);
127+
void t2() { two({{1, 2}}); } // ill-formed; previously well-formed
128+
129+
void *a[10];
130+
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
131+
any b[10];
132+
int y = span<const any>{b, b + 10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
133+
\end{codeblock}
134+
110135
\rSec1[diff.cpp20]{\Cpp{} and ISO \CppXX{}}
111136

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

source/containers.tex

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

1822218222
\indexheader{span}%
1822318223
\begin{codeblock}
18224+
#include <initializer_list> // see \ref{initializer.list.syn}
18225+
1822418226
namespace std {
1822518227
// constants
1822618228
inline constexpr size_t @\libglobal{dynamic_extent}@ = numeric_limits<size_t>::max();
@@ -18292,6 +18294,7 @@
1829218294
constexpr span(const array<T, N>& arr) noexcept;
1829318295
template<class R>
1829418296
constexpr explicit(extent != dynamic_extent) span(R&& r);
18297+
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
1829518298
constexpr span(const span& other) noexcept = default;
1829618299
template<class OtherElementType, size_t OtherExtent>
1829718300
constexpr explicit(@\seebelow@) span(const span<OtherElementType, OtherExtent>& s) noexcept;
@@ -18542,6 +18545,27 @@
1854218545
What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw.
1854318546
\end{itemdescr}
1854418547

18548+
\indexlibraryctor{span}%
18549+
\begin{itemdecl}
18550+
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
18551+
\end{itemdecl}
18552+
18553+
\begin{itemdescr}
18554+
\pnum
18555+
\constraints
18556+
\tcode{is_const_v<element_type>} is \tcode{true}.
18557+
18558+
\pnum
18559+
\expects
18560+
If \tcode{extent} is not equal to \tcode{dynamic_extent}, then
18561+
\tcode{il.size()} is equal to \tcode{extent}.
18562+
18563+
\pnum
18564+
\effects
18565+
Initializes \exposid{data_} with \tcode{il.begin()} and
18566+
\exposid{size_} with \tcode{il.size()}.
18567+
\end{itemdescr}
18568+
1854518569
\indexlibraryctor{span}%
1854618570
\begin{itemdecl}
1854718571
constexpr span(const span& other) noexcept = default;

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@
762762
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
763763
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}
764764
#define @\defnlibxname{cpp_lib_span}@ 202002L // also in \libheader{span}
765+
#define @\defnlibxname{cpp_lib_span_initializer_list}@ 202311L // also in \libheader{span}
765766
#define @\defnlibxname{cpp_lib_spanstream}@ 202106L // also in \libheader{spanstream}
766767
#define @\defnlibxname{cpp_lib_ssize}@ 201902L // freestanding, also in \libheader{iterator}
767768
#define @\defnlibxname{cpp_lib_sstream_from_string_view}@ 202306L // also in \libheader{sstream}

0 commit comments

Comments
 (0)