[range.elements.iterator]

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

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

### 25.7.23 Elements view [[range.elements]](range.elements#iterator)

#### 25.7.23.3 Class template elements_view​::​*iterator* [range.elements.iterator]

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

namespace std::ranges {template<[input_range](range.refinements#concept:input_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> && [*has-tuple-element*](range.elements.view#concept:has-tuple-element "25.7.23.2 Class template elements_­view [range.elements.view]")<range_value_t<V>, N> &&[*has-tuple-element*](range.elements.view#concept:has-tuple-element "25.7.23.2 Class template elements_­view [range.elements.view]")<remove_reference_t<range_reference_t<V>>, N> &&[*returnable-element*](range.elements.view#concept:returnable-element "25.7.23.2 Class template elements_­view [range.elements.view]")<range_reference_t<V>, N>template<bool Const>class elements_view<V, N>::*iterator* {using *Base* = *maybe-const*<Const, V>; // *exposition only* iterator_t<*Base*> *current_* = iterator_t<*Base*>(); // *exposition only*static constexpr decltype(auto) *get-element*(const iterator_t<*Base*>& i); // *exposition only*public:using iterator_concept = *see below*; using iterator_category = *see below*; // not always presentusing value_type = remove_cvref_t<tuple_element_t<N, range_value_t<*Base*>>>; using difference_type = range_difference_t<*Base*>; *iterator*() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<iterator_t<*Base*>> = default; constexpr explicit *iterator*(iterator_t<*Base*> current); 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 const iterator_t<*Base*>& base() const & noexcept; constexpr iterator_t<*Base*> base() &&; constexpr decltype(auto) operator*() const{ return *get-element*(*current_*); }constexpr *iterator*& operator++(); constexpr void operator++(int); constexpr *iterator* operator++(int) requires [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]")<*Base*>; 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 decltype(auto) operator[](difference_type n) constrequires [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<*Base*>{ return *get-element*(*current_* + n); }friend constexpr bool operator==(const *iterator*& x, const *iterator*& y)requires [equality_comparable](concept.equalitycomparable#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<iterator_t<*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 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*& x, difference_type y)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 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 *iterator* operator-(const *iterator*& x, difference_type y)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*>>; };}

[1](#1)

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

The member [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") 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, if *Base* models [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]"),
then iterator_concept denotes forward_iterator_tag[.](#1.3.sentence-1)

- [(1.4)](#1.4)

  Otherwise, iterator_concept denotes input_iterator_tag[.](#1.4.sentence-1)

[2](#2)

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

The member [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") iterator_category is defined
if and only if *Base* models [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]")[.](#2.sentence-1)

In that case, iterator_category is defined as follows:
Let C denote the typeiterator_traits<iterator_t<*Base*>>​::​iterator_category[.](#2.sentence-2)

- [(2.1)](#2.1)

  If std​::​get<N>(**current_*) is an rvalue,iterator_category denotes input_iterator_tag[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  Otherwise, if C models [derived_from](concept.derived#concept:derived_from "18.4.3 Concept derived_­from [concept.derived]")<random_access_iterator_tag>,iterator_category denotes random_access_iterator_tag[.](#2.2.sentence-1)

- [(2.3)](#2.3)

  Otherwise, iterator_category denotes C[.](#2.3.sentence-1)

[ð](#lib:get-element,elements_view::iterator)

`static constexpr decltype(auto) get-element(const iterator_t<Base>& i);
`

[3](#3)

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

*Effects*: Equivalent to:if constexpr (is_reference_v<range_reference_t<*Base*>>) {return std::get<N>(*i);} else {using E = remove_cv_t<tuple_element_t<N, range_reference_t<*Base*>>>; return static_cast<E>(std::get<N>(*i));}

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

`constexpr explicit iterator(iterator_t<Base> current);
`

[4](#4)

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

*Effects*: Initializes *current_* with std​::​move(current)[.](#4.sentence-1)

[ð](#lib:elements_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#L10419)

*Effects*: Initializes *current_* with std​::​move(i.*current_*)[.](#5.sentence-1)

[ð](#lib:base,elements_view::iterator)

`constexpr const iterator_t<Base>& base() const & noexcept;
`

[6](#6)

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

*Effects*: Equivalent to: return *current_*;

[ð](#lib:base,elements_view::iterator_)

`constexpr iterator_t<Base> base() &&;
`

[7](#7)

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

*Effects*: Equivalent to: return std​::​move(*current_*);

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

`constexpr iterator& operator++();
`

[8](#8)

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

*Effects*: Equivalent to:++*current_*;return *this;

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

`constexpr void operator++(int);
`

[9](#9)

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

*Effects*: Equivalent to: ++*current_*[.](#9.sentence-1)

[ð](#lib:operator++,elements_view::iterator__)

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

[10](#10)

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

*Effects*: Equivalent to:auto temp = *this;++*current_*;return temp;

[ð](#lib:operator--,elements_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#L10494)

*Effects*: Equivalent to:--*current_*;return *this;

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

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

[12](#12)

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

*Effects*: Equivalent to:auto temp = *this;--*current_*;return temp;

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

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

[13](#13)

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

*Effects*: Equivalent to:*current_* += n;return *this;

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

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

[14](#14)

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

*Effects*: Equivalent to:*current_* -= n;return *this;

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

`friend constexpr bool operator==(const iterator& x, const iterator& y)
  requires [equality_comparable](concept.equalitycomparable#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<Base>;
`

[15](#15)

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

*Effects*: Equivalent to: return x.*current_* == y.*current_*;

[ð](#lib:operator%3c,elements_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>;
`

[16](#16)

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

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

[ð](#lib:operator%3e,elements_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>;
`

[17](#17)

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

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

[ð](#lib:operator%3c=,elements_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>;
`

[18](#18)

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

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

[ð](#lib:operator%3e=,elements_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>;
`

[19](#19)

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

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

[ð](#lib:operator%3c=%3e,elements_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>>;
`

[20](#20)

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

*Effects*: Equivalent to: return x.*current_* <=> y.*current_*;

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

`friend constexpr iterator operator+(const iterator& x, difference_type y)
  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#L10630)

*Effects*: Equivalent to: return *iterator*{x} += y;

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

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

[22](#22)

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

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

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

`friend constexpr iterator operator-(const iterator& x, difference_type 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#L10654)

*Effects*: Equivalent to: return *iterator*{x} -= y;

[ð](#lib:operator-,elements_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>>;
`

[24](#24)

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

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