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

4.8 KiB
Raw Permalink Blame History

[range.drop.while]

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.13 Drop while view [range.drop.while]

25.7.13.1 Overview [range.drop.while.overview]

1

#

Given a unary predicate pred and a view r,drop_while_view produces a view of the range [ranges::find_if_not(r, pred), ranges::end(r)).

2

#

The name views::drop_while denotes a range adaptor object ([range.adaptor.object]).

Given subexpressions E and F, the expression views::drop_while(E, F) is expression-equivalent to drop_while_view(E, F).

3

#

[Example 1: constexpr auto source = " \t \t \t hello there"sv;auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; };auto skip_ws = views::drop_while(source, is_invisible);for (auto c : skip_ws) { cout << c; // prints hello there with no leading space} — end example]

25.7.13.2 Class template drop_while_view [range.drop.while.view]

🔗

namespace std::ranges {template<view V, class Pred>requires input_range && is_object_v &&indirect_unary_predicate<const Pred, iterator_t>class drop_while_view : public view_interface<drop_while_view<V, Pred>> {public: drop_while_view() requires default_initializable && default_initializable = default; constexpr explicit drop_while_view(V base, Pred pred); constexpr V base() const & requires copy_constructible { return base_; }constexpr V base() && { return std::move(base_); }constexpr const Pred& pred() const; constexpr auto begin(); constexpr auto end() { return ranges::end(base_); }private: V base_ = V(); // exposition only**movable-box pred_; // exposition only}; template<class R, class Pred> drop_while_view(R&&, Pred) -> drop_while_view<views::all_t, Pred>;}

🔗

constexpr explicit drop_while_view(V base, Pred pred);

1

#

Effects: Initializes base_ with std::move(base) andpred_ with std::move(pred).

🔗

constexpr const Pred& pred() const;

2

#

Effects: Equivalent to: return **pred_*;

🔗

constexpr auto begin();

3

#

Preconditions: pred_.has_value() is true.

4

#

Returns: ranges::find_if_not(base_, cref(**pred_*)).

5

#

Remarks: In order to provide the amortized constant-time complexity required by the range concept when drop_while_view models forward_range, the first call caches the result within the drop_while_view for use on subsequent calls.

[Note 1:

Without this, applying a reverse_view over a drop_while_view would have quadratic iteration complexity.

— end note]