Skip to content

Commit f45473e

Browse files
authored
Merge 2019-11 LWG Motion 13
P1394R4 Range constructor for std::span
2 parents d558fc9 + 25738f7 commit f45473e

File tree

1 file changed

+109
-41
lines changed

1 file changed

+109
-41
lines changed

source/containers.tex

Lines changed: 109 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,84 @@
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+
Let \tcode{U} be \tcode{remove_reference_t<iter_reference_t<It>>}.
10680+
\begin{itemize}
10681+
\item \tcode{It} satisfies \libconcept{contiguous_iterator}.
10682+
\item
10683+
\tcode{is_convertible_v<U(*)[], element_type(*)[]>} is \tcode{true}.
10684+
\begin{note}
10685+
The intent is to allow only qualification conversions
10686+
of the iterator reference type to \tcode{element_type}.
10687+
\end{note}
10688+
\end{itemize}
10689+
1067610690
\pnum
1067710691
\expects
10678-
\range{ptr}{ptr + count} is a valid range.
10692+
\begin{itemize}
10693+
\item \range{first}{first + count} is a valid range.
10694+
\item \tcode{It} models \libconcept{contiguous_iterator}.
10695+
\item
1067910696
If \tcode{extent} is not equal to \tcode{dynamic_extent},
1068010697
then \tcode{count} is equal to \tcode{extent}.
10698+
\end{itemize}
1068110699

1068210700
\pnum
1068310701
\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}.
10702+
Initializes \tcode{data_} with \tcode{to_address(first)} and
10703+
\tcode{size_} with \tcode{count}.
1068910704

1069010705
\pnum
1069110706
\throws
10692-
Nothing.
10707+
When and what \tcode{to_address(first)} throws.
1069310708
\end{itemdescr}
1069410709

1069510710
\indexlibraryctor{span}%
1069610711
\begin{itemdecl}
10697-
constexpr span(pointer first, pointer last);
10712+
template<class It, class End>
10713+
constexpr span(It first, End last);
1069810714
\end{itemdecl}
1069910715

1070010716
\begin{itemdescr}
1070110717
\pnum
10718+
\constraints
10719+
Let \tcode{U} be \tcode{remove_reference_t<iter_reference_t<It>>}.
10720+
\begin{itemize}
10721+
\item
10722+
\tcode{is_convertible_v<U(*)[], element_type(*)[]>} is \tcode{true}.
10723+
\begin{note}
10724+
The intent is to allow only qualification conversions
10725+
of the iterator reference type to \tcode{element_type}.
10726+
\end{note}
10727+
\item \tcode{It} satisfies \libconcept{contiguous_iterator}.
10728+
\item \tcode{End} satisfies \tcode{\libconcept{sized_sentinel_for}<It>}.
10729+
\item \tcode{is_convertible_v<End, size_t>} is \tcode{false}.
10730+
\end{itemize}
10731+
1070210732
\expects
10703-
\range{first}{last} is a valid range.
10733+
\begin{itemize}
10734+
\item
1070410735
If \tcode{extent} is not equal to \tcode{dynamic_extent},
1070510736
then \tcode{last - first} is equal to \tcode{extent}.
10737+
\item \range{first}{last} is a valid range.
10738+
\item \tcode{It} models \libconcept{contiguous_iterator}.
10739+
\item \tcode{End} models \tcode{\libconcept{sized_sentinel_for}<It>}.
10740+
\end{itemize}
1070610741

1070710742
\pnum
1070810743
\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}.
10744+
Initializes \tcode{data_} with \tcode{to_address(first)} and
10745+
\tcode{size_} with \tcode{last - first}.
1071410746

1071510747
\pnum
1071610748
\throws
10717-
Nothing.
10749+
When and what \tcode{to_address(first)} throws.
1071810750
\end{itemdescr}
1071910751

1072010752
\indexlibraryctor{span}%
@@ -10743,37 +10775,47 @@
1074310775

1074410776
\indexlibraryctor{span}%
1074510777
\begin{itemdecl}
10746-
template<class Container> constexpr span(Container& cont);
10747-
template<class Container> constexpr span(const Container& cont);
10778+
template<class R> constexpr span(R&& r);
1074810779
\end{itemdecl}
1074910780

1075010781
\begin{itemdescr}
1075110782
\pnum
1075210783
\constraints
10784+
Let \tcode{U} be \tcode{remove_reference_t<ranges::range_reference_t<R>>}.
1075310785
\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(*)[]}.
10786+
\item \tcode{extent == dynamic_extent} is \tcode{true}.
10787+
\item \tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}} and
10788+
\tcode{ranges::\libconcept{sized_range}}.
10789+
\item Either \tcode{R} satisfies \exposconcept{forwarding-range} or
10790+
\tcode{is_const_v<element_type>} is \tcode{true}.
10791+
\item \tcode{remove_cvref_t<R>} is not a specialization of \tcode{span}.
10792+
\item \tcode{remove_cvref_t<R>} is not a specialization of \tcode{array}.
10793+
\item \tcode{is_array_v<remove_cvref_t<R>>} is \tcode{false}.
10794+
\item
10795+
\tcode{is_convertible_v<U(*)[], element_type(*)[]>} is \tcode{true}.
10796+
\begin{note}
10797+
The intent is to allow only qualification conversions
10798+
of the iterator reference type to \tcode{element_type}.
10799+
\end{note}
1076010800
\end{itemize}
1076110801

1076210802
\pnum
1076310803
\expects
10764-
\range{data(cont)}{data(cont) + size(cont)} is a valid range.
10804+
\begin{itemize}
10805+
\item \tcode{R} models \tcode{ranges::\libconcept{contiguous_range}} and
10806+
\tcode{ranges::\libconcept{sized_range}}.
10807+
\item If \tcode{is_const_v<element_type>} is \tcode{false},
10808+
\tcode{R} models \exposconcept{forwarding-range}.
10809+
\end{itemize}
1076510810

1076610811
\pnum
1076710812
\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)}.
10813+
Initializes \tcode{data_} with \tcode{ranges::data(r)} and
10814+
\tcode{size_} with \tcode{ranges::size(r)}.
1077310815

1077410816
\pnum
1077510817
\throws
10776-
What and when \tcode{data(cont)} and \tcode{size(cont)} throw.
10818+
What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw.
1077710819
\end{itemdescr}
1077810820

1077910821
\indexlibraryctor{span}%
@@ -10822,6 +10864,32 @@
1082210864
\tcode{size() == other.size() \&\& data() == other.data()}.
1082310865
\end{itemdescr}
1082410866

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

1082710895
\indexlibrarymember{span}{first}%

0 commit comments

Comments
 (0)