[range.iota.iterator]

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

## 25.6 Range factories [[range.factories]](range.factories#range.iota.iterator)

### 25.6.4 Iota view [[range.iota]](range.iota#iterator)

#### 25.6.4.3 Class iota_view​::​*iterator* [range.iota.iterator]

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

namespace std::ranges {template<[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") W, [semiregular](concepts.object#concept:semiregular "18.6 Object concepts [concepts.object]") Bound>requires [*weakly-equality-comparable-with*](concept.equalitycomparable#concept:weakly-equality-comparable-with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<W, Bound> && [copyable](concepts.object#concept:copyable "18.6 Object concepts [concepts.object]")<W>struct iota_view<W, Bound>::*iterator* {private: W *value_* = W(); // *exposition only*public:using iterator_concept = *see below*; using iterator_category = input_iterator_tag; // present only if W models [incrementable](iterator.concept.inc#concept:incrementable "24.3.4.5 Concept incrementable [iterator.concept.inc]") and// *IOTA-DIFF-T*(W) is an integral typeusing value_type = W; using difference_type = *IOTA-DIFF-T*(W); *iterator*() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<W> = default; constexpr explicit *iterator*(W value); constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>); constexpr *iterator*& operator++(); constexpr void operator++(int); constexpr *iterator* operator++(int) requires [incrementable](iterator.concept.inc#concept:incrementable "24.3.4.5 Concept incrementable [iterator.concept.inc]")<W>; constexpr *iterator*& operator--() requires [*decrementable*](range.iota.view#concept:decrementable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; constexpr *iterator* operator--(int) requires [*decrementable*](range.iota.view#concept:decrementable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; constexpr *iterator*& operator+=(difference_type n)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; constexpr *iterator*& operator-=(difference_type n)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; constexpr W operator[](difference_type n) constrequires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; 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]")<W>; friend constexpr bool operator<(const *iterator*& x, const *iterator*& y)requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>; friend constexpr bool operator>(const *iterator*& x, const *iterator*& y)requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>; friend constexpr bool operator<=(const *iterator*& x, const *iterator*& y)requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>; friend constexpr bool operator>=(const *iterator*& x, const *iterator*& y)requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>; friend constexpr auto operator<=>(const *iterator*& x, const *iterator*& y)requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W> && [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<W>; friend constexpr *iterator* operator+(*iterator* i, difference_type n)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; friend constexpr *iterator* operator+(difference_type n, *iterator* i)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; friend constexpr *iterator* operator-(*iterator* i, difference_type n)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; friend constexpr difference_type operator-(const *iterator*& x, const *iterator*& y)requires [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>; };}

[1](#1)

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

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

- [(1.1)](#1.1)

  If W models [*advanceable*](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]"), theniterator_concept is random_access_iterator_tag[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  Otherwise, if W models [*decrementable*](range.iota.view#concept:decrementable "25.6.4.2 Class template iota_­view [range.iota.view]"), theniterator_concept is bidirectional_iterator_tag[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  Otherwise, if W models [incrementable](iterator.concept.inc#concept:incrementable "24.3.4.5 Concept incrementable [iterator.concept.inc]"), theniterator_concept is forward_iterator_tag[.](#1.3.sentence-1)

- [(1.4)](#1.4)

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

[2](#2)

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

[*Note [1](#note-1)*:

Overloads for iter_move and iter_swap are omitted intentionally[.](#2.sentence-1)

â *end note*]

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

`constexpr explicit iterator(W value);
`

[3](#3)

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

*Effects*: Initializes *value_* with value[.](#3.sentence-1)

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

`constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
`

[4](#4)

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

*Effects*: Equivalent to: return *value_*;

[5](#5)

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

[*Note [2](#note-2)*:

The noexcept clause is needed by the default iter_move implementation[.](#5.sentence-1)

â *end note*]

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

`constexpr iterator& operator++();
`

[6](#6)

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

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

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

`constexpr void operator++(int);
`

[7](#7)

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

*Effects*: Equivalent to ++*this[.](#7.sentence-1)

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

`constexpr iterator operator++(int) requires [incrementable](iterator.concept.inc#concept:incrementable "24.3.4.5 Concept incrementable [iterator.concept.inc]")<W>;
`

[8](#8)

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

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

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

`constexpr iterator& operator--() requires [decrementable](range.iota.view#concept:decrementable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[9](#9)

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

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

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

`constexpr iterator operator--(int) requires [decrementable](range.iota.view#concept:decrementable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[10](#10)

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

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

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

`constexpr iterator& operator+=(difference_type n)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[11](#11)

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

*Effects*: Equivalent to:if constexpr (*is-integer-like*<W> && !*is-signed-integer-like*<W>) {if (n >= difference_type(0))*value_* += static_cast<W>(n); else*value_* -= static_cast<W>(-n);} else {*value_* += n;}return *this;

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

`constexpr iterator& operator-=(difference_type n)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[12](#12)

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

*Effects*: Equivalent to:if constexpr (*is-integer-like*<W> && !*is-signed-integer-like*<W>) {if (n >= difference_type(0))*value_* -= static_cast<W>(n); else*value_* += static_cast<W>(-n);} else {*value_* -= n;}return *this;

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

`constexpr W operator[](difference_type n) const
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[13](#13)

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

*Effects*: Equivalent to: return W(*value_* + n);

[ð](#lib:operator==,iota_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]")<W>;
`

[14](#14)

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

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

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

`friend constexpr bool operator<(const iterator& x, const iterator& y)
  requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>;
`

[15](#15)

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

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

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

`friend constexpr bool operator>(const iterator& x, const iterator& y)
  requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>;
`

[16](#16)

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

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

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

`friend constexpr bool operator<=(const iterator& x, const iterator& y)
  requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>;
`

[17](#17)

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

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

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

`friend constexpr bool operator>=(const iterator& x, const iterator& y)
  requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W>;
`

[18](#18)

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

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

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

`friend constexpr auto operator<=>(const iterator& x, const iterator& y)
  requires [totally_ordered](concept.totallyordered#concept:totally_ordered "18.5.5 Concept totally_­ordered [concept.totallyordered]")<W> && [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<W>;
`

[19](#19)

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

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

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

`friend constexpr iterator operator+(iterator i, difference_type n)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[20](#20)

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

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

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

`friend constexpr iterator operator+(difference_type n, iterator i)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[21](#21)

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

*Effects*: Equivalent to: return i + n;

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

`friend constexpr iterator operator-(iterator i, difference_type n)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[22](#22)

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

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

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

`friend constexpr difference_type operator-(const iterator& x, const iterator& y)
  requires [advanceable](range.iota.view#concept:advanceable "25.6.4.2 Class template iota_­view [range.iota.view]")<W>;
`

[23](#23)

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

*Effects*: Equivalent to:using D = difference_type;if constexpr (*is-integer-like*<W>) {if constexpr (*is-signed-integer-like*<W>)return D(D(x.*value_*) - D(y.*value_*)); elsereturn (y.*value_* > x.*value_*)? D(-D(y.*value_* - x.*value_*)): D(x.*value_* - y.*value_*);} else {return x.*value_* - y.*value_*;}
