24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.10 Drop while view [range.drop.while]

24.7.10.1 Overview [range.drop.while.overview]

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)).
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}.
[Example 1: constexpr auto source = " \t \t \t hello there"; auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; }; auto skip_ws = drop_while_view{source, is_invisible}; for (auto c : skip_ws) { cout << c; // prints hello there with no leading space } — end example]

24.7.10.2 Class template drop_­while_­view [range.drop.while.view]

namespace std::ranges { template<view V, class Pred> requires input_­range<V> && is_object_v<Pred> && indirect_­unary_­predicate<const Pred, iterator_t<V>> class drop_while_view : public view_interface<drop_while_view<V, Pred>> { public: drop_while_view() = default; constexpr drop_while_view(V base, Pred pred); constexpr V base() const& requires copy_­constructible<V> { 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 semiregular-box<Pred> pred_; // exposition only }; template<class R, class Pred> drop_while_view(R&&, Pred) -> drop_while_view<views::all_t<R>, Pred>; }
constexpr drop_while_view(V base, Pred pred);
Effects: Initializes base_­ with std​::​move(base) and pred_­ with std​::​move(pred).
constexpr const Pred& pred() const;
Effects: Equivalent to: return *pred_­;
constexpr auto begin();
Preconditions: pred_­.has_­value() is true.
Returns: ranges​::​find_­if_­not(base_­, cref(*pred_­)).
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]