24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.21 Adjacent view [range.adjacent]

24.7.21.2 Class template adjacent_­view [range.adjacent.view]

namespace std::ranges { template<forward_­range V, size_t N> requires view<V> && (N > 0) class adjacent_view : public view_interface<adjacent_view<V, N>> { V base_ = V(); // exposition only // [range.adjacent.iterator], class template adjacent_­view​::​iterator template<bool> class iterator; // exposition only // [range.adjacent.sentinel], class template adjacent_­view​::​sentinel template<bool> class sentinel; // exposition only struct as-sentinel{}; // exposition only public: adjacent_view() requires default_­initializable<V> = default; constexpr explicit adjacent_view(V base); constexpr auto begin() requires (!simple-view<V>) { return iterator<false>(ranges::begin(base_), ranges::end(base_)); } constexpr auto begin() const requires range<const V> { return iterator<true>(ranges::begin(base_), ranges::end(base_)); } constexpr auto end() requires (!simple-view<V>) { if constexpr (common_­range<V>) { return iterator<false>(as-sentinel{}, ranges::begin(base_), ranges::end(base_)); } else { return sentinel<false>(ranges::end(base_)); } } constexpr auto end() const requires range<const V> { if constexpr (common_­range<const V>) { return iterator<true>(as-sentinel{}, ranges::begin(base_), ranges::end(base_)); } else { return sentinel<true>(ranges::end(base_)); } } constexpr auto size() requires sized_­range<V>; constexpr auto size() const requires sized_­range<const V>; }; }
constexpr explicit adjacent_view(V base);
Effects: Initializes base_­ with std​::​move(base).
constexpr auto size() requires sized_­range<V>; constexpr auto size() const requires sized_­range<const V>;
Effects: Equivalent to: using ST = decltype(ranges::size(base_)); using CT = common_type_t<ST, size_t>; auto sz = static_cast<CT>(ranges::size(base_)); sz -= std::min<CT>(sz, N - 1); return static_cast<ST>(sz);