24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.21 Adjacent view [range.adjacent]

24.7.21.3 Class template adjacent_­view​::​iterator [range.adjacent.iterator]

namespace std::ranges { template<forward_­range V, size_t N> requires view<V> && (N > 0) template<bool Const> class adjacent_view<V, N>::iterator { using Base = maybe-const<Const, V>; // exposition only array<iterator_t<Base>, N> current_ = array<iterator_t<Base>, N>(); // exposition only constexpr iterator(iterator_t<Base> first, sentinel_t<Base> last); // exposition only constexpr iterator(as-sentinel, iterator_t<Base> first, iterator_t<Base> last); // exposition only public: using iterator_category = input_iterator_tag; using iterator_concept = see below; using value_type = tuple-or-pair<REPEAT(range_value_t<Base>, N)...>; using difference_type = range_difference_t<Base>; iterator() = default; constexpr iterator(iterator<!Const> i) requires Const && convertible_­to<iterator_t<V>, iterator_t<Base>>; constexpr auto operator*() const; constexpr iterator& operator++(); constexpr iterator operator++(int); constexpr iterator& operator--() requires bidirectional_­range<Base>; constexpr iterator operator--(int) requires bidirectional_­range<Base>; constexpr iterator& operator+=(difference_type x) requires random_­access_­range<Base>; constexpr iterator& operator-=(difference_type x) requires random_­access_­range<Base>; constexpr auto operator[](difference_type n) const requires random_­access_­range<Base>; friend constexpr bool operator==(const iterator& x, const iterator& y); friend constexpr bool operator<(const iterator& x, const iterator& y) requires random_­access_­range<Base>; friend constexpr bool operator>(const iterator& x, const iterator& y) requires random_­access_­range<Base>; friend constexpr bool operator<=(const iterator& x, const iterator& y) requires random_­access_­range<Base>; friend constexpr bool operator>=(const iterator& x, const iterator& y) requires random_­access_­range<Base>; friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires random_­access_­range<Base> && three_­way_­comparable<iterator_t<Base>>; friend constexpr iterator operator+(const iterator& i, difference_type n) requires random_­access_­range<Base>; friend constexpr iterator operator+(difference_type n, const iterator& i) requires random_­access_­range<Base>; friend constexpr iterator operator-(const iterator& i, difference_type n) requires random_­access_­range<Base>; friend constexpr difference_type operator-(const iterator& x, const iterator& y) requires sized_­sentinel_­for<iterator_t<Base>, iterator_t<Base>>; friend constexpr auto iter_move(const iterator& i) noexcept(see below); friend constexpr void iter_swap(const iterator& l, const iterator& r) noexcept(see below) requires indirectly_­swappable<iterator_t<Base>>; }; }
iterator​::​iterator_­concept is defined as follows:
If the invocation of any non-const member function of iterator exits via an exception, the iterator acquires a singular value.
constexpr iterator(iterator_t<Base> first, sentinel_t<Base> last);
Postconditions: current_­[0] == first is true, and for every integer , current_­[i] == ranges​::​next(current_­[i-1], 1, last) is true.
constexpr iterator(as-sentinel, iterator_t<Base> first, iterator_t<Base> last);
Postconditions: If Base does not model bidirectional_­range, each element of current_­ is equal to last.
Otherwise, current_­[N-1] == last is true, and for every integer , current_­[i] == ranges​::​prev(current_­[i+1], 1, first) is true.
constexpr iterator(iterator<!Const> i) requires Const && convertible_­to<iterator_t<V>, iterator_t<Base>>;
Effects: Initializes each element of current_­ with the corresponding element of i.current_­ as an xvalue.
constexpr auto operator*() const;
Effects: Equivalent to: return tuple-transform([](auto& i) -> decltype(auto) { return *i; }, current_);
constexpr iterator& operator++();
Preconditions: current_­.back() is incrementable.
Postconditions: Each element of current_­ is equal to ranges​::​next(i), where i is the value of that element before the call.
Returns: *this.
constexpr iterator operator++(int);
Preconditions: Equivalent to: auto tmp = *this; ++*this; return tmp;
constexpr iterator& operator--() requires bidirectional_­range<Base>;
Preconditions: current_­.front() is decrementable.
Postconditions: Each element of current_­ is equal to ranges​::​prev(i), where i is the value of that element before the call.
Returns: *this.
constexpr iterator operator--(int) requires bidirectional_­range<Base>;
Effects: Equivalent to: auto tmp = *this; --*this; return tmp;
constexpr iterator& operator+=(difference_type x) requires random_­access_­range<Base>;
Preconditions: current_­.back() + x has well-defined behavior.
Postconditions: Each element of current_­ is equal to i + x, where i is the value of that element before the call.
Returns: *this.
constexpr iterator& operator-=(difference_type x) requires random_­access_­range<Base>;
Preconditions: current_­.front() - x has well-defined behavior.
Postconditions: Each element of current_­ is equal to i - x, where i is the value of that element before the call.
Returns: *this.
constexpr auto operator[](difference_type n) const requires random_­access_­range<Base>;
Effects: Equivalent to: return tuple-transform([&](auto& i) -> decltype(auto) { return i[n]; }, current_);
friend constexpr bool operator==(const iterator& x, const iterator& y);
Returns: x.current_­.back() == y.current_­.back().
friend constexpr bool operator<(const iterator& x, const iterator& y) requires random_­access_­range<Base>;
Returns: x.current_­.back() < y.current_­.back().
friend constexpr bool operator>(const iterator& x, const iterator& y) requires random_­access_­range<Base>;
Effects: Equivalent to: return y < x;
friend constexpr bool operator<=(const iterator& x, const iterator& y) requires random_­access_­range<Base>;
Effects: Equivalent to: return !(y < x);
friend constexpr bool operator>=(const iterator& x, const iterator& y) requires random_­access_­range<Base>;
Effects: Equivalent to: return !(x < y);
friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires random_­access_­range<Base> && three_­way_­comparable<iterator_t<Base>>;
Returns: x.current_­.back() <=> y.current_­.back().
friend constexpr iterator operator+(const iterator& i, difference_type n) requires random_­access_­range<Base>; friend constexpr iterator operator+(difference_type n, const iterator& i) requires random_­access_­range<Base>;
Effects: Equivalent to: auto r = i; r += n; return r;
friend constexpr iterator operator-(const iterator& i, difference_type n) requires random_­access_­range<Base>;
Effects: Equivalent to: auto r = i; r -= n; return r;
friend constexpr difference_type operator-(const iterator& x, const iterator& y) requires sized_­sentinel_­for<iterator_t<Base>, iterator_t<Base>>;
Effects: Equivalent to: return x.current_­.back() - y.current_­.back();
friend constexpr auto iter_move(const iterator& i) noexcept(see below);
Effects: Equivalent to: return tuple-transform(ranges​::​iter_­move, i.current_­);
Remarks: The exception specification is equivalent to: noexcept(ranges::iter_move(declval<const iterator_t<Base>&>())) && is_nothrow_move_constructible_v<range_rvalue_reference_t<Base>>
friend constexpr void iter_swap(const iterator& l, const iterator& r) noexcept(see below) requires indirectly_­swappable<iterator_t<Base>>;
Preconditions: None of the iterators in l.current_­ is equal to an iterator in r.current_­.
Effects: For every integer , performs ranges​::​iter_­swap(l.current_­[i], r.current_­[i]).
Remarks: The exception specification is equivalent to: noexcept(ranges::iter_swap(declval<iterator_t<Base>>(), declval<iterator_t<Base>>()))