Skip to content

Commit b8e3922

Browse files
authored
Merge 2020-02 LWG Motion 24
P1739R4 Avoid template bloat for safe_ranges in combination with "subrange-y" view adaptors
2 parents b1e8f5a + 12a6300 commit b8e3922

File tree

1 file changed

+90
-24
lines changed

1 file changed

+90
-24
lines changed

source/ranges.tex

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,7 @@
20382038
constexpr explicit iota_view(W value);
20392039
constexpr iota_view(type_identity_t<W> value,
20402040
type_identity_t<Bound> bound);
2041+
constexpr iota_view(@\exposid{iterator}@ first, @\exposid{sentinel}@ last) : iota_view(*first, last.@\exposid{bound_}@) {}
20412042

20422043
constexpr @\exposid{iterator}@ begin() const;
20432044
constexpr auto end() const;
@@ -2048,7 +2049,7 @@
20482049

20492050
template<class W, class Bound>
20502051
requires (!@\exposconcept{is-integer-like}@<W> || !@\exposconcept{is-integer-like}@<Bound> ||
2051-
(@\exposconcept{is-signed-integer-like}@<W> == @\exposconcept{is-signed-integer-like}@<Bound>))
2052+
(@\exposconcept{is-signed-integer-like}@<W> == @\exposconcept{is-signed-integer-like}@<Bound>))
20522053
iota_view(W, Bound) -> iota_view<W, Bound>;
20532054
}
20542055
\end{codeblock}
@@ -4206,9 +4207,37 @@
42064207
\pnum
42074208
The name \tcode{views::take} denotes a
42084209
range adaptor object\iref{range.adaptor.object}.
4209-
Given subexpressions \tcode{E} and \tcode{F}, the expression
4210-
\tcode{views::take(E, F)} is expression-equivalent to
4211-
\tcode{take_view\{E, F\}}.
4210+
Let \tcode{E} and \tcode{F} be expressions,
4211+
let \tcode{T} be \tcode{remove_cvref_t<decltype((E))>}, and
4212+
let \tcode{D} be \tcode{range_difference_t<decltype((E))>}.
4213+
If \tcode{decltype((F))} does not model
4214+
\tcode{\libconcept{convertible_to}<D>},
4215+
\tcode{views::take(E, F)} is ill-formed.
4216+
Otherwise, the expression \tcode{views::take(E, F)}
4217+
is expression-equivalent to:
4218+
4219+
\begin{itemize}
4220+
\item
4221+
If \tcode{T} is a specialization
4222+
of \tcode{ranges::empty_view}\iref{range.empty.view},
4223+
then \tcode{((void) F, \placeholdernc{decay-copy}(E))}.
4224+
4225+
\item
4226+
Otherwise, if \tcode{T} models
4227+
\libconcept{random_access_range} and \libconcept{sized_range}
4228+
and is
4229+
\begin{itemize}
4230+
\item a specialization of \tcode{span}\iref{views.span} where \tcode{T::extent == dynamic_extent},
4231+
\item a specialization of \tcode{basic_string_view}\iref{string.view},
4232+
\item a specialization of \tcode{ranges::iota_view}\iref{range.iota.view}, or
4233+
\item a specialization of \tcode{ranges::subrange}\iref{range.subrange},
4234+
\end{itemize}
4235+
then \tcode{T\{ranges::begin(E), ranges::begin(E) + min<D>(ranges::size(E), F)\}},
4236+
except that \tcode{E} is evaluated only once.
4237+
4238+
\item
4239+
Otherwise, \tcode{ranges::take_view\{E, F\}}.
4240+
\end{itemize}
42124241

42134242
\pnum
42144243
\begin{example}
@@ -4560,9 +4589,37 @@
45604589
\pnum
45614590
The name \tcode{views::drop} denotes
45624591
a range adaptor object\iref{range.adaptor.object}.
4563-
Given subexpressions \tcode{E} and \tcode{F},
4564-
the expression \tcode{views::drop(E, F)}
4565-
is expression-equivalent to \tcode{drop_view\{E, F\}}.
4592+
Let \tcode{E} and \tcode{F} be expressions,
4593+
let \tcode{T} be \tcode{remove_cvref_t<decltype((E))>}, and
4594+
let \tcode{D} be \tcode{range_difference_t<decltype((E))>}.
4595+
If \tcode{decltype((F))} does not model
4596+
\tcode{\libconcept{convertible_to}<D>},
4597+
\tcode{views::drop(E, F)} is ill-formed.
4598+
Otherwise, the expression \tcode{views::drop(E, F)}
4599+
is expression-equivalent to:
4600+
4601+
\begin{itemize}
4602+
\item
4603+
If \tcode{T} is a specialization of
4604+
\tcode{ranges::empty_view}\iref{range.empty.view},
4605+
then \tcode{((void) F, \placeholdernc{decay-copy}(E))}.
4606+
4607+
\item
4608+
Otherwise, if \tcode{T} models
4609+
\libconcept{random_access_range} and \libconcept{sized_range}
4610+
and is
4611+
\begin{itemize}
4612+
\item a specialization of \tcode{span}\iref{views.span} where \tcode{T::extent == dynamic_extent},
4613+
\item a specialization of \tcode{basic_string_view}\iref{string.view},
4614+
\item a specialization of \tcode{ranges::iota_view}\iref{range.iota.view}, or
4615+
\item a specialization of \tcode{ranges::subrange}\iref{range.subrange},
4616+
\end{itemize}
4617+
then \tcode{T\{ranges::begin(E) + min<D>(ranges::size(E), F), ranges::end(E)\}},
4618+
except that \tcode{E} is evaluated only once.
4619+
4620+
\item
4621+
Otherwise, \tcode{ranges::drop_view\{E, F\}}.
4622+
\end{itemize}
45664623

45674624
\pnum
45684625
\begin{example}
@@ -5773,26 +5830,35 @@
57735830
for an iterator \tcode{i} and non-negative integer \tcode{n}.
57745831

57755832
\pnum
5776-
The name \tcode{views::counted} denotes a
5777-
customization point object\iref{customization.point.object}.
5833+
The name \tcode{views::counted} denotes
5834+
a customization point object\iref{customization.point.object}.
57785835
Let \tcode{E} and \tcode{F} be expressions,
5779-
and let \tcode{T} be \tcode{decay_t<decltype((E))>}.
5780-
Then the expression \tcode{views::counted(E, F)} is expression-equivalent to:
5836+
let \tcode{T} be \tcode{decay_t<decltype((E))>}, and
5837+
let \tcode{D} be \tcode{iter_difference_t<T>}.
5838+
If \tcode{decltype((F))} does not model
5839+
\tcode{\libconcept{convertible_to}<D>},
5840+
\tcode{views::counted(E, F)} is ill-formed.
5841+
\begin{note}
5842+
This case can result in substitution failure
5843+
when \tcode{views::counted(E, F)}
5844+
appears in the immediate context of a template instantiation.
5845+
\end{note}
5846+
Otherwise, \tcode{views::counted(E, F)}
5847+
is expression-equivalent to:
5848+
57815849
\begin{itemize}
5782-
\item If \tcode{T} models \libconcept{input_or_output_iterator} and
5783-
\tcode{decltype((F))} models \tcode{\libconcept{convertible_to}<iter_differ\-ence_t<T>>},
5784-
\begin{itemize}
5785-
\item \tcode{subrange\{E, E + static_cast<iter_difference_t<T>>(F)\}}
5786-
if \tcode{T} models \libconceptx{random_access_\-it\-er\-ator}{random_access_iterator}.
5787-
\item Otherwise,
5788-
\tcode{subrange\{counted_iterator\{E, F\}, default_sentinel\}}.
5789-
\end{itemize}
5850+
\item
5851+
If \tcode{T} models \libconcept{contiguous_iterator},
5852+
then \tcode{span\{to_address(E), static_cast<D>(F)\}}.
57905853

5791-
\item Otherwise, \tcode{views::counted(E, F)} is ill-formed.
5792-
\begin{note}
5793-
This case can result in substitution failure when \tcode{views::counted(E, F)}
5794-
appears in the immediate context of a template instantiation.
5795-
\end{note}
5854+
\item
5855+
Otherwise, if \tcode{T} models \libconcept{random_access_iterator},
5856+
then \tcode{subrange\{E, E + static_cast<D>(F)\}},
5857+
except that \tcode{E} is evaluated only once.
5858+
5859+
\item
5860+
Otherwise,
5861+
\tcode{subrange\{counted_iterator\{E, F\}, default_sentinel\}}.
57965862
\end{itemize}
57975863

57985864
\rSec2[range.common]{Common view}

0 commit comments

Comments
 (0)