3.9 KiB
[range.drop.overview]
25 Ranges library [ranges]
25.7 Range adaptors [range.adaptors]
25.7.12 Drop view [range.drop]
25.7.12.1 Overview [range.drop.overview]
drop_view produces a view excluding the first N elements from another view, or an empty range if the adapted view contains fewer than N elements.
The name views::drop denotes a range adaptor object ([range.adaptor.object]).
Let E and F be expressions, let T be remove_cvref_t<decltype((E))>, and let D be range_difference_t<decltype((E))>.
If decltype((F)) does not modelconvertible_to,views::drop(E, F) is ill-formed.
Otherwise, the expression views::drop(E, F) is expression-equivalent to:
-
If T is a specialization ofempty_view ([range.empty.view]), then ((void)F, decay-copy(E)), except that the evaluations of E and F are indeterminately sequenced.
-
Otherwise, if T modelsrandom_access_range and sized_range and is
a specialization of span ([views.span]),
a specialization of basic_string_view ([string.view]),
a specialization of iota_view ([range.iota.view]), or
a specialization of subrange ([range.subrange]) where T::StoreSize is false,
then U(ranges::begin(E) + std::min(ranges::distance(E), F), ranges::end(E)), except that E is evaluated only once, where U is span<typename T::element_type> if T is a specialization of span and T otherwise.
-
Otherwise, if T is a specialization of subrange that models random_access_range and sized_range, thenT(ranges::begin(E) + std::min(ranges::distance(E), F), ranges::end(E),to-unsigned-like(ranges::distance(E) - std::min(ranges::distance(E), F))), except that E and F are each evaluated only once.
-
Otherwise, if T is a specialization of repeat_view ([range.repeat.view]):
if T models sized_range, thenviews::repeat(*E.value_, ranges::distance(E) - std::min(ranges::distance(E), F)) except that E is evaluated only once;
otherwise, ((void)F, decay-copy(E)), except that the evaluations of E and F are indeterminately sequenced.
[Example 1: auto ints = views::iota(0) | views::take(10);for (auto i : ints | views::drop(5)) { cout << i << ' '; // prints 5 6 7 8 9} â end example]