24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.4 Filter view [range.filter]

24.7.4.2 Class template filter_­view [range.filter.view]

namespace std::ranges {
  template<InputRange V, IndirectUnaryPredicate<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();              // exposition only
    semiregular<Pred> pred_;    // exposition only

    // [range.filter.iterator], class filter_­view​::​iterator
    class iterator;             // exposition only
    // [range.filter.sentinel], class filter_­view​::​sentinel
    class sentinel;             // exposition only

  public:
    filter_view() = default;
    constexpr filter_view(V base, Pred pred);
    template<InputRange R>
      requires ViewableRange<R> && Constructible<V, all_view<R>>
    constexpr filter_view(R&& r, Pred pred);

    constexpr V base() const;

    constexpr iterator begin();
    constexpr auto end() {
      if constexpr (CommonRange<V>)
        return iterator{*this, ranges::end(base_)};
      else
        return sentinel{*this};
    }
  };

  template<class R, class Pred>
    filter_view(R&&, Pred) -> filter_view<all_view<R>, Pred>;
}
constexpr filter_view(V base, Pred pred);
Effects: Initializes base_­ with std::move(base) and initializes pred_­ with std::move(pred).
template<InputRange R> requires ViewableRange<R> && Constructible<V, all_view<R>> constexpr filter_view(R&& r, Pred pred);
Effects: Initializes base_­ with view::all(std::forward<R>(r)) and initializes pred_­ with std::​move(pred).
constexpr V base() const;
Effects: Equivalent to: return base_­;
constexpr iterator begin();
Expects: pred_­.has_­value().
Returns: {*this, ranges::find_­if(base_­, ref(*pred_­))}.
Remarks: In order to provide the amortized constant time complexity required by the Range concept, this function caches the result within the filter_­view for use on subsequent calls.