Files
2025-10-25 03:02:53 +03:00

3.9 KiB
Raw Permalink Blame History

[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]

1

#

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.

2

#

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:

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.

  • (2.3)

    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.

  • (2.4)

    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.

  • (2.5)

    Otherwise, drop_view(E, F).

3

#

[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]