Skip to content

[LWG 9] P2447R6 std::span over an initializer list #6691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@
// changed according to the global C locale
\end{codeblock}

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

\diffref{span.overview}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it typical to only specify the class synopsis
instead of the parent subclause that also encompasses the detailed specifications?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They did the same thing for cpp20, so I guess so?

\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 @@ -18221,6 +18221,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 @@ -18292,6 +18294,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 @@ -18542,6 +18545,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 @@ -762,6 +762,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