[range.filter.view] (original) (raw)

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.8 Filter view [range.filter]

25.7.8.2 Class template filter_view [range.filter.view]

namespace std::ranges { template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred> requires view<V> && is_object_v<Pred> class filter_view : public view_interface<filter_view<V, Pred>> { private: V base_ = V(); movable-box<Pred> pred_; class iterator; class sentinel; public: filter_view() requires default_initializable<V> && default_initializable<Pred> = default;constexpr explicit filter_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 iterator begin();constexpr auto end() { if constexpr (common_range<V>) return iterator{*this, ranges::end(base_)};else return sentinel{*this};} };template<class R, class Pred> filter_view(R&&, Pred) -> filter_view<views::all_t<R>, Pred>;}

constexpr explicit filter_view(V base, Pred pred);

Effects: Initializes base_ with std​::​move(base) and initializes_pred__ with std​::​move(pred).

constexpr const Pred& pred() const;

Effects: Equivalent to: return *pred_;

constexpr _iterator_ begin();

Preconditions: pred_.has_value() is true.

Returns: {*this, ranges​::​find_if(base_, ref(*pred_))}.

Remarks: In order to provide the amortized constant time complexity required by the range concept when filter_view models forward_range, this function caches the result within thefilter_view for use on subsequent calls.