24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.14 Split view [range.split]

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

namespace std::ranges { template<forward_­range V, forward_­range Pattern> requires view<V> && view<Pattern> && indirectly_­comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> class split_view : public view_interface<split_view<V, Pattern>> { private: V base_ = V(); // exposition only Pattern pattern_ = Pattern(); // exposition only // [range.split.iterator], class split_­view​::​iterator struct iterator; // exposition only // [range.split.sentinel], class split_­view​::​sentinel struct sentinel; // exposition only public: split_view() requires default_­initializable<V> && default_­initializable<Pattern> = default; constexpr split_view(V base, Pattern pattern); template<forward_­range R> requires constructible_­from<V, views::all_t<R>> && constructible_­from<Pattern, single_view<range_value_t<R>>> constexpr split_view(R&& r, range_value_t<R> e); constexpr V base() const& requires copyable<V> { return base_; } constexpr V base() && { return std::move(base_); } constexpr iterator begin(); constexpr auto end() { if constexpr (common_­range<V>) { return iterator{*this, ranges::end(base_), {}}; } else { return sentinel{*this}; } } constexpr subrange<iterator_t<V>> find-next(iterator_t<V>); // exposition only }; template<class R, class P> split_view(R&&, P&&) -> split_view<views::all_t<R>, views::all_t<P>>; template<forward_­range R> split_view(R&&, range_value_t<R>) -> split_view<views::all_t<R>, single_view<range_value_t<R>>>; }
constexpr split_view(V base, Pattern pattern);
Effects: Initializes base_­ with std​::​move(base), and pattern_­ with std​::​move(pattern).
template<forward_­range R> requires constructible_­from<V, views::all_t<R>> && constructible_­from<Pattern, single_view<range_value_t<R>>> constexpr split_view(R&& r, range_value_t<R> e);
Effects: Initializes base_­ with views​::​all(std​::​forward<R>(r)), and pattern_­ with views​::​
single(std​::​move(e))
.
constexpr iterator begin();
Returns: {*this, ranges​::​begin(base_­), find-next(ranges​::​begin(base_­))}.
Remarks: In order to provide the amortized constant time complexity required by the range concept, this function caches the result within the split_­view for use on subsequent calls.
constexpr subrange<iterator_t<V>> find-next(iterator_t<V> it); // exposition only
Effects: Equivalent to: auto [b, e] = ranges::search(subrange(it, ranges::end(base_)), pattern_); if (b != ranges::end(base_) && ranges::empty(pattern_)) { ++b; ++e; } return {b, e};