Skip to content

Commit

Permalink
P2447R6 std::span over an initializer list
Browse files Browse the repository at this point in the history
  • Loading branch information
burblebee committed Nov 15, 2023
1 parent ecbeb5a commit 71562b2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@
// changed according to the global C locale
\end{codeblock}

\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}

\diffref{span.overview}
\change
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
\rationale
Permit passing a braced initializer list to a function taking \tcode{span}.
\effect
Valid \CppXXIII{} code that relies on the lack of this constructor
may refuse to compile, or change behavior in this revision of \Cpp{}.
For example:
\begin{codeblock}
void one(pair<int, int>); // \#1
void one(span<const int>); // \#2
void t1() { one({1,2}); } // ambiguous between \#1 and \#2; previously called \#1

void two(span<const int, 2>);
void t2() { two({{1,2}}); } // ill-formed; previously well-formed

void *a[10];
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
any b[10];
int y = span<const any>{b, b+10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
\end{codeblock}

\rSec1[diff.cpp20]{\Cpp{} and ISO \CppXX{}}

\rSec2[diff.cpp20.general]{General}
Expand Down
24 changes: 24 additions & 0 deletions source/containers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -18218,6 +18218,8 @@

\indexheader{span}%
\begin{codeblock}
#include <initializer_list> // see \ref{initializer.list.syn}

namespace std {
// constants
inline constexpr size_t @\libglobal{dynamic_extent}@ = numeric_limits<size_t>::max();
Expand Down Expand Up @@ -18289,6 +18291,7 @@
constexpr span(const array<T, N>& arr) noexcept;
template<class R>
constexpr explicit(extent != dynamic_extent) span(R&& r);
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
constexpr span(const span& other) noexcept = default;
template<class OtherElementType, size_t OtherExtent>
constexpr explicit(@\seebelow@) span(const span<OtherElementType, OtherExtent>& s) noexcept;
Expand Down Expand Up @@ -18533,6 +18536,27 @@
What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw.
\end{itemdescr}

\indexlibraryctor{span}%
\begin{itemdecl}
constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
\end{itemdecl}

\begin{itemdescr}
\pnum
\constraints
\tcode{is_const_v<element_type>} is \tcode{true}.

\pnum
\expects
If \tcode{extent} is not equal to \tcode{dynamic_extent}, then
\tcode{il.size()} is equal to \tcode{extent}.

\pnum
\effects
Initializes \exposid{data_} with \tcode{il.begin()} and
\exposid{size_} with \tcode{il.size()}.
\end{itemdescr}

\indexlibraryctor{span}%
\begin{itemdecl}
constexpr span(const span& other) noexcept = default;
Expand Down
1 change: 1 addition & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}
#define @\defnlibxname{cpp_lib_span}@ 202002L // also in \libheader{span}
#define @\defnlibxname{cpp_lib_span_initializer_list}@ 202311L // also in \libheader{span}
#define @\defnlibxname{cpp_lib_spanstream}@ 202106L // also in \libheader{spanstream}
#define @\defnlibxname{cpp_lib_ssize}@ 201902L // freestanding, also in \libheader{iterator}
#define @\defnlibxname{cpp_lib_sstream_from_string_view}@ 202306L // also in \libheader{sstream}
Expand Down

0 comments on commit 71562b2

Please sign in to comment.