23 Ranges library [ranges]

23.8 Range adaptors [range.adaptors]

23.8.8 Split view [range.split]

23.8.8.2 Class template split_­view [range.split.view]

namespace std::ranges {
  template<auto> struct require-constant;       // exposition only

  template<class R>
  concept tiny-range =                          // exposition only
    SizedRange<R> &&
    requires { typename require-constant<remove_reference_t<R>::size()>; } &&
    (remove_reference_t<R>::size() <= 1);

  template<InputRange V, ForwardRange Pattern>
    requires View<V> && View<Pattern> &&
             IndirectlyComparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to<>> &&
             (ForwardRange<V> || tiny-range<Pattern>)
  class split_view : public view_interface<split_view<V, Pattern>> {
  private:
    V base_ = V();                              // exposition only
    Pattern pattern_ = Pattern();               // exposition only
    iterator_t<V> current_ = iterator_t<V>();   // exposition only, present only if !ForwardRange<V>
    template<bool> struct outer_iterator;       // exposition only
    template<bool> struct inner_iterator;       // exposition only
  public:
    split_view() = default;
    constexpr split_view(V base, Pattern pattern);

    template<InputRange R, ForwardRange P>
      requires Constructible<V, all_view<R>> &&
               Constructible<Pattern, all_view<P>>
    constexpr split_view(R&& r, P&& p);

    template<InputRange R>
      requires Constructible<V, all_view<R>> &&
               Constructible<Pattern, single_view<iter_value_t<iterator_t<R>>>>
    constexpr split_view(R&& r, iter_value_t<iterator_t<R>> e);

    constexpr auto begin() {
      if constexpr (ForwardRange<V>)
        return outer_iterator<simple-view<V>>{*this, ranges::begin(base_)};
      else {
        current_ = ranges::begin(base_);
        return outer_iterator<false>{*this};
      }
    }

    constexpr auto begin() const requires ForwardRange<V> && ForwardRange<const V> {
      return outer_iterator<true>{*this, ranges::begin(base_)};
    }

    constexpr auto end() requires ForwardRange<V> && CommonRange<V> {
      return outer_iterator<simple-view<V>>{*this, ranges::end(base_)};
    }

    constexpr auto end() const {
      if constexpr (ForwardRange<V> && ForwardRange<const V> && CommonRange<const V>)
        return outer_iterator<true>{*this, ranges::end(base_)};
      else
        return default_sentinel;
    }
  };

  template<class R, class P>
    split_view(R&&, P&&) -> split_view<all_view<R>, all_view<P>>;

  template<InputRange R>
    split_view(R&&, iter_value_t<iterator_t<R>>)
      -> split_view<all_view<R>, single_view<iter_value_t<iterator_t<R>>>>;
}
constexpr split_view(V base, Pattern pattern);
Effects: Initializes base_­ with std::move(base), and pattern_­ with std::move(pattern).
template<InputRange R, ForwardRange P> requires Constructible<V, all_view<R>> && Constructible<Pattern, all_view<P>> constexpr split_view(R&& r, P&& p);
Effects: Initializes base_­ with view::all(std::forward<R>(r)) and pattern_­ with view::all(std​::forward<P>(p)).
template<InputRange R> requires Constructible<V, all_view<R>> && Constructible<Pattern, single_view<iter_value_t<iterator_t<R>>>> constexpr split_view(R&& r, iter_value_t<iterator_t<R>> e);
Effects: Initializes base_­ with view::all(std::forward<R>(r)) and pattern_­ with single_­view{​std::move(e)}.