Skip to content

Commit d2a42fb

Browse files
jensmaurerzygoloid
authored andcommitted
P1394R4 Range constructor for std::span
Converted run-on sentences in bulleted lists to one sentence per bullet. Fixes NB US 233, US 246, PL 251 (C++20 CD).
1 parent d558fc9 commit d2a42fb

File tree

1 file changed

+115
-41
lines changed

1 file changed

+115
-41
lines changed

source/containers.tex

Lines changed: 115 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10571,18 +10571,18 @@
1057110571

1057210572
// \ref{span.cons}, constructors, copy, and assignment
1057310573
constexpr span() noexcept;
10574-
constexpr span(pointer ptr, size_type count);
10575-
constexpr span(pointer first, pointer last);
10574+
template<class It>
10575+
constexpr span(It first, size_type count);
10576+
tmeplate<class It, class End>
10577+
constexpr span(It first, End last);
1057610578
template<size_t N>
1057710579
constexpr span(element_type (&arr)[N]) noexcept;
1057810580
template<size_t N>
1057910581
constexpr span(array<value_type, N>& arr) noexcept;
1058010582
template<size_t N>
1058110583
constexpr span(const array<value_type, N>& arr) noexcept;
10582-
template<class Container>
10583-
constexpr span(Container& cont);
10584-
template<class Container>
10585-
constexpr span(const Container& cont);
10584+
template<class R>
10585+
constexpr span(R&& r);
1058610586
constexpr span(const span& other) noexcept = default;
1058710587
template<class OtherElementType, size_t OtherExtent>
1058810588
constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
@@ -10633,16 +10633,16 @@
1063310633
size_type size_; // \expos
1063410634
};
1063510635

10636+
template<class It, class End>
10637+
span(It, End) -> span<remove_reference_t<iter_reference_t<It>>>;
1063610638
template<class T, size_t N>
1063710639
span(T (&)[N]) -> span<T, N>;
1063810640
template<class T, size_t N>
1063910641
span(array<T, N>&) -> span<T, N>;
1064010642
template<class T, size_t N>
1064110643
span(const array<T, N>&) -> span<const T, N>;
10642-
template<class Container>
10643-
span(Container&) -> span<typename Container::value_type>;
10644-
template<class Container>
10645-
span(const Container&) -> span<const typename Container::value_type>;
10644+
template<class R>
10645+
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
1064610646
}
1064710647
\end{codeblock}
1064810648

@@ -10669,52 +10669,88 @@
1066910669

1067010670
\indexlibraryctor{span}%
1067110671
\begin{itemdecl}
10672-
constexpr span(pointer ptr, size_type count);
10672+
template<class It>
10673+
constexpr span(It first, size_type count);
1067310674
\end{itemdecl}
1067410675

1067510676
\begin{itemdescr}
10677+
\pnum
10678+
\constraints
10679+
\begin{itemize}
10680+
\item \tcode{It} satisfies \libconcept{contiguous_iterator}.
10681+
\item
10682+
\begin{codeblock}
10683+
{is_convertible_v<remove_reference_t<iter_reference_t<It>>(*)[], element_type(*)[]>
10684+
\end{codeblock}
10685+
is \tcode{true}.
10686+
\begin{note}
10687+
The intent is to allow only qualification conversions
10688+
of the iterator reference type to \tcode{element_type}.
10689+
\end{note}
10690+
\end{itemize}
10691+
1067610692
\pnum
1067710693
\expects
10678-
\range{ptr}{ptr + count} is a valid range.
10694+
\begin{itemize}
10695+
\item \range{first}{first + count} is a valid range.
10696+
\item \tcode{It} models \libconcept{contiguous_iterator}.
10697+
\item
1067910698
If \tcode{extent} is not equal to \tcode{dynamic_extent},
1068010699
then \tcode{count} is equal to \tcode{extent}.
10700+
\end{itemize}
1068110701

1068210702
\pnum
1068310703
\effects
10684-
Constructs a \tcode{span} that is a view over the range \range{ptr}{ptr + count}.
10685-
10686-
\pnum
10687-
\ensures
10688-
\tcode{size() == count \&\& data() == ptr}.
10704+
Initializes \tcode{data_} with \tcode{to_address(first)} and
10705+
\tcode{size_} with \tcode{first + count}.
1068910706

1069010707
\pnum
1069110708
\throws
10692-
Nothing.
10709+
When and what \tcode{to_address(first)} throws.
1069310710
\end{itemdescr}
1069410711

1069510712
\indexlibraryctor{span}%
1069610713
\begin{itemdecl}
10697-
constexpr span(pointer first, pointer last);
10714+
template<class It, class End>
10715+
constexpr span(It first, End last);
1069810716
\end{itemdecl}
1069910717

1070010718
\begin{itemdescr}
1070110719
\pnum
10720+
\constraints
10721+
\begin{itemize}
10722+
\item
10723+
\begin{codeblock}
10724+
is_convertible_v<remove_reference_t<iter_reference_t<It>>(*)[], element_type(*)[]>
10725+
\end{codeblock}
10726+
is \tcode{true}.
10727+
\begin{note}
10728+
The intent is to allow only qualification conversions
10729+
of the iterator reference type to \tcode{element_type}.
10730+
\end{note}
10731+
\item \tcode{It} satisfies \libconcept{contiguous_iterator}.
10732+
\item \tcode{End} satisfies \tcode{\libconcept{sized_sentinel_for}<It>}.
10733+
\item \tcode{is_convertible_v<End, size_t>} is \tcode{false}.
10734+
\end{itemize}
10735+
1070210736
\expects
10703-
\range{first}{last} is a valid range.
10737+
\begin{itemize}
10738+
\item
1070410739
If \tcode{extent} is not equal to \tcode{dynamic_extent},
1070510740
then \tcode{last - first} is equal to \tcode{extent}.
10741+
\item \range{first}{last} is a valid range.
10742+
\item \tcode{It} models \libconcept{contiguous_iterator}.
10743+
\item \tcode{End} models \tcode{\libconcept{sized_sentinel_for}<It>}.
10744+
\end{itemize}
1070610745

1070710746
\pnum
1070810747
\effects
10709-
Constructs a span that is a view over the range \range{first}{last}.
10710-
10711-
\pnum
10712-
\ensures
10713-
\tcode{size() == last - first \&\& data() == first}.
10748+
Initializes \tcode{data_} with \tcode{to_address(first)} and
10749+
\tcode{size_} with \tcode{last - first}.
1071410750

1071510751
\pnum
1071610752
\throws
10717-
Nothing.
10753+
When and what \tcode{to_address(first)} throws.
1071810754
\end{itemdescr}
1071910755

1072010756
\indexlibraryctor{span}%
@@ -10743,37 +10779,49 @@
1074310779

1074410780
\indexlibraryctor{span}%
1074510781
\begin{itemdecl}
10746-
template<class Container> constexpr span(Container& cont);
10747-
template<class Container> constexpr span(const Container& cont);
10782+
template<class R> constexpr span(R&& r);
1074810783
\end{itemdecl}
1074910784

1075010785
\begin{itemdescr}
1075110786
\pnum
1075210787
\constraints
1075310788
\begin{itemize}
10754-
\item \tcode{extent == dynamic_extent} is \tcode{true},
10755-
\item \tcode{Container} is not a specialization of \tcode{span},
10756-
\item \tcode{Container} is not a specialization of \tcode{array},
10757-
\item \tcode{is_array_v<Container>} is \tcode{false},
10758-
\item \tcode{data(cont)} and \tcode{size(cont)} are both well-formed, and
10759-
\item \tcode{remove_pointer_t<decltype(data(cont))>(*)[]} is convertible to \tcode{ElementType(*)[]}.
10789+
\item \tcode{extent == dynamic_extent} is \tcode{true}.
10790+
\item \tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}} and
10791+
\tcode{ranges::\libconcept{sized_range}}.
10792+
\item Either \tcode{R} satisfies \exposconcept{forwarding-range} or
10793+
\tcode{is_const_v<element_type>} is \tcode{true}.
10794+
\item \tcode{remove_cvref_t<R>} is not a specialization of \tcode{span}.
10795+
\item \tcode{remove_cvref_t<R>} is not a specialization of \tcode{array}.
10796+
\item \tcode{is_array_v<remove_cvref_t<R>>} is \tcode{false}.
10797+
\item\relax
10798+
\begin{codeblock}
10799+
is_convertible_v<remove_reference_t<ranges::range_reference_t<R>>(*)[], element_type(*)[]>
10800+
\end{codeblock}
10801+
is \tcode{true}.
10802+
\begin{note}
10803+
The intent is to allow only qualification conversions
10804+
of the iterator reference type to \tcode{element_type}.
10805+
\end{note}
1076010806
\end{itemize}
1076110807

1076210808
\pnum
1076310809
\expects
10764-
\range{data(cont)}{data(cont) + size(cont)} is a valid range.
10810+
\begin{itemize}
10811+
\item \tcode{R} models \tcode{ranges::\libconcept{contiguous_range}} and
10812+
\tcode{ranges::\libconcept{sized_range}}.
10813+
\item If \tcode{is_const_v<element_type>} is \tcode{false},
10814+
\tcode{R} models \exposconcept{forwarding-range}.
10815+
\end{itemize}
1076510816

1076610817
\pnum
1076710818
\effects
10768-
Constructs a \tcode{span} that is a view over the range \range{data(cont)}{data(cont) + size(cont)}.
10769-
10770-
\pnum
10771-
\ensures
10772-
\tcode{size() == size(cont) \&\& data() == data(cont)}.
10819+
Initializes \tcode{data_} with \tcode{ranges::data(r)} and
10820+
\tcode{size_} with \tcode{ranges::size(r)}.
1077310821

1077410822
\pnum
1077510823
\throws
10776-
What and when \tcode{data(cont)} and \tcode{size(cont)} throw.
10824+
What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw.
1077710825
\end{itemdescr}
1077810826

1077910827
\indexlibraryctor{span}%
@@ -10822,6 +10870,32 @@
1082210870
\tcode{size() == other.size() \&\& data() == other.data()}.
1082310871
\end{itemdescr}
1082410872

10873+
\rSec3[span.deduct]{Deduction guides}
10874+
10875+
\indexlibrary{\idxcode{span}!deduction guide}%
10876+
\begin{itemdecl}
10877+
template <class It, class End>
10878+
span(It, End) -> span<remove_reference_t<iter_reference_t<It>>>;
10879+
\end{itemdecl}
10880+
10881+
\begin{itemdescr}
10882+
\pnum
10883+
\constraints
10884+
\tcode{It} satisfies \libconcept{contiguous_iterator}.
10885+
\end{itemdescr}
10886+
10887+
\indexlibrary{\idxcode{span}!deduction guide}%
10888+
\begin{itemdecl}
10889+
template<class R>
10890+
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
10891+
\end{itemdecl}
10892+
10893+
\begin{itemdescr}
10894+
\pnum
10895+
\constraints
10896+
\tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}}.
10897+
\end{itemdescr}
10898+
1082510899
\rSec3[span.sub]{Subviews}
1082610900

1082710901
\indexlibrarymember{span}{first}%

0 commit comments

Comments
 (0)