[range.adjacent.iterator]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.adjacent.iterator)

### 25.7.27 Adjacent view [[range.adjacent]](range.adjacent#iterator)

#### 25.7.27.3 Class template adjacent_view​::​*iterator* [range.adjacent.iterator]

[ð](#lib:adjacent_view::iterator)

namespace std::ranges {template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") V, size_t N>requires [view](range.view#concept:view "25.4.5 Views [range.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<*REPEAT*(range_value_t<*Base*>, N)...>; using difference_type = range_difference_t<*Base*>; *iterator*() = default; constexpr *iterator*(*iterator*<!Const> i)requires Const && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<iterator_t<V>, iterator_t<*Base*>>; constexpr auto operator*() const; constexpr *iterator*& operator++(); constexpr *iterator* operator++(int); constexpr *iterator*& operator--() requires [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; constexpr *iterator* operator--(int) requires [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; constexpr *iterator*& operator+=(difference_type x)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; constexpr *iterator*& operator-=(difference_type x)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; constexpr auto operator[](difference_type n) constrequires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*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](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr bool operator>(const *iterator*& x, const *iterator*& y)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr bool operator<=(const *iterator*& x, const *iterator*& y)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr bool operator>=(const *iterator*& x, const *iterator*& y)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr auto operator<=>(const *iterator*& x, const *iterator*& y)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*> &&[three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<iterator_t<*Base*>>; friend constexpr *iterator* operator+(const *iterator*& i, difference_type n)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr *iterator* operator+(difference_type n, const *iterator*& i)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr *iterator* operator-(const *iterator*& i, difference_type n)requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; friend constexpr difference_type operator-(const *iterator*& x, const *iterator*& y)requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<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](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<iterator_t<*Base*>>; };}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12753)

*iterator*​::​iterator_concept is defined as follows:

- [(1.1)](#1.1)

  If *Base* models [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]"),
then iterator_concept denotes random_access_iterator_tag[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  Otherwise, if *Base* models [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]"),
then iterator_concept denotes bidirectional_iterator_tag[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  Otherwise, iterator_concept denotes forward_iterator_tag[.](#1.3.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12766)

If the invocation of any non-const member function of *iterator* exits via an exception, the *iterator* acquires a singular value[.](#2.sentence-1)

[ð](#lib:adjacent_view::iterator,constructor)

`constexpr iterator(iterator_t<Base> first, sentinel_t<Base> last);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12776)

*Postconditions*: *current_*[0] == first is true, and
for every integer 1â¤i<N,*current_*[i] == ranges​::​next(*current_*[i-1], 1, last) is true[.](#3.sentence-1)

[ð](#lib:adjacent_view::iterator,constructor_)

`constexpr iterator(as-sentinel, iterator_t<Base> first, iterator_t<Base> last);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12790)

*Postconditions*: If *Base* does not model [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]"),
each element of *current_* is equal to *last*[.](#4.sentence-1)

Otherwise, *current_*[N-1] == last is true, and
for every integer 0â¤i<(Nâ1),*current_*[i] == ranges​::​prev(*current_*[i+1], 1, first) is true[.](#4.sentence-2)

[ð](#lib:adjacent_view::iterator,constructor__)

`constexpr iterator(iterator<!Const> i)
  requires Const && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<iterator_t<V>, iterator_t<Base>>;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12807)

*Effects*: Initializes each element of *current_* with the corresponding element of i.*current_* as an xvalue[.](#5.sentence-1)

[ð](#lib:operator*,adjacent_view::iterator)

`constexpr auto operator*() const;
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12819)

*Effects*: Equivalent to:return *tuple-transform*([](auto& i) -> decltype(auto) { return *i; }, *current_*);

[ð](#lib:operator++,adjacent_view::iterator)

`constexpr iterator& operator++();
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12833)

*Preconditions*: *current_*.back() is incrementable[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12837)

*Postconditions*: Each element of *current_* is equal to ranges​::​next(i),
where i is the value of that element before the call[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12842)

*Returns*: *this[.](#9.sentence-1)

[ð](#lib:operator++,adjacent_view::iterator_)

`constexpr iterator operator++(int);
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12853)

*Effects*: Equivalent to:auto tmp = *this;++*this;return tmp;

[ð](#lib:operator--,adjacent_view::iterator)

`constexpr iterator& operator--() requires [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12869)

*Preconditions*: *current_*.front() is decrementable[.](#11.sentence-1)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12873)

*Postconditions*: Each element of *current_* is equal to ranges​::​prev(i),
where i is the value of that element before the call[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12878)

*Returns*: *this[.](#13.sentence-1)

[ð](#lib:operator--,adjacent_view::iterator_)

`constexpr iterator operator--(int) requires [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12889)

*Effects*: Equivalent to:auto tmp = *this;--*this;return tmp;

[ð](#lib:operator+=,adjacent_view::iterator)

`constexpr iterator& operator+=(difference_type x)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12906)

*Preconditions*: *current_*.back() + x has well-defined behavior[.](#15.sentence-1)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12910)

*Postconditions*: Each element of *current_* is equal to i + x,
where i is the value of that element before the call[.](#16.sentence-1)

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12915)

*Returns*: *this[.](#17.sentence-1)

[ð](#lib:operator-=,adjacent_view::iterator)

`constexpr iterator& operator-=(difference_type x)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12927)

*Preconditions*: *current_*.front() - x has well-defined behavior[.](#18.sentence-1)

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12931)

*Postconditions*: Each element of *current_* is equal to i - x,
where i is the value of that element before the call[.](#19.sentence-1)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12936)

*Returns*: *this[.](#20.sentence-1)

[ð](#lib:operator%5b%5d,adjacent_view::iterator)

`constexpr auto operator[](difference_type n) const
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12948)

*Effects*: Equivalent to:return *tuple-transform*([&](auto& i) -> decltype(auto) { return i[n]; }, *current_*);

[ð](#lib:operator==,adjacent_view::iterator)

`friend constexpr bool operator==(const iterator& x, const iterator& y);
`

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12962)

*Returns*: x.*current_*.back() == y.*current_*.back()[.](#22.sentence-1)

[ð](#lib:operator%3c,adjacent_view::iterator)

`friend constexpr bool operator<(const iterator& x, const iterator& y)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12974)

*Returns*: x.*current_*.back() < y.*current_*.back()[.](#23.sentence-1)

[ð](#lib:operator%3e,adjacent_view::iterator)

`friend constexpr bool operator>(const iterator& x, const iterator& y)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12986)

*Effects*: Equivalent to: return y < x;

[ð](#lib:operator%3c=,adjacent_view::iterator)

`friend constexpr bool operator<=(const iterator& x, const iterator& y)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12998)

*Effects*: Equivalent to: return !(y < x);

[ð](#lib:operator%3e=,adjacent_view::iterator)

`friend constexpr bool operator>=(const iterator& x, const iterator& y)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[26](#26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13010)

*Effects*: Equivalent to: return !(x < y);

[ð](#lib:operator%3c=%3e,adjacent_view::iterator)

`friend constexpr auto operator<=>(const iterator& x, const iterator& y)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base> &&
           [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<iterator_t<Base>>;
`

[27](#27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13023)

*Returns*: x.*current_*.back() <=> y.*current_*.back()[.](#27.sentence-1)

[ð](#lib:operator+,adjacent_view::iterator)

`friend constexpr iterator operator+(const iterator& i, difference_type n)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
friend constexpr iterator operator+(difference_type n, const iterator& i)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[28](#28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13037)

*Effects*: Equivalent to:auto r = i;
r += n;return r;

[ð](#lib:operator-,adjacent_view::iterator)

`friend constexpr iterator operator-(const iterator& i, difference_type n)
  requires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<Base>;
`

[29](#29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13054)

*Effects*: Equivalent to:auto r = i;
r -= n;return r;

[ð](#lib:operator-,adjacent_view::iterator_)

`friend constexpr difference_type operator-(const iterator& x, const iterator& y)
  requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<iterator_t<Base>, iterator_t<Base>>;
`

[30](#30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13071)

*Effects*: Equivalent to:return x.*current_*.back() - y.*current_*.back();

[ð](#lib:iter_move,adjacent_view::iterator)

`friend constexpr auto iter_move(const iterator& i) noexcept(see below);
`

[31](#31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13083)

*Effects*: Equivalent to:return *tuple-transform*(ranges​::​iter_move, i.*current_*);

[32](#32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13088)

*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*>>

[ð](#lib:iter_swap,adjacent_view::iterator)

`friend constexpr void iter_swap(const iterator& l, const iterator& r) noexcept(see below)
  requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<iterator_t<Base>>;
`

[33](#33)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13104)

*Preconditions*: None of the iterators in l.*current_* is equal to
an iterator in r.*current_*[.](#33.sentence-1)

[34](#34)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13109)

*Effects*: For every integer 0â¤i<N,
performsranges​::​iter_swap(l.*current_*[i], r.*current_*[i])[.](#34.sentence-1)

[35](#35)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L13115)

*Remarks*: The exception specification is equivalent to:noexcept(ranges::iter_swap(declval<iterator_t<*Base*>>(), declval<iterator_t<*Base*>>()))
