std::ranges::iota_view<W, Bound>::iterator - cppreference.com (original) (raw)

struct /*iterator*/; (1) (exposition only*)
Helper alias templates
template< class I > using /*iota-diff-t*/ = /* see below */; (2) (exposition only*)
Helper concepts
template< class I > concept /*decrementable*/ = std::incrementable<I> && requires(I i) { { --i } -> std::same_as<I&>; { i-- } -> std::same_as<I>; }; (3) (exposition only*)
template< class I > concept /*advanceable*/ = /*decrementable*/<I> && std::totally_ordered<I> && requires(I i, const I j, const /*iota-diff-t*/<I> n) { { i += n } -> std::same_as<I&>; { i -= n } -> std::same_as<I&>; I(j + n); I(n + j); I(j - n); { j - j } -> std::convertible_to</*iota-diff-t*/<I>>; }; (4) (exposition only*)
  1. Calculates the difference type for both iterator types and integer-like types.
  1. Specifies that a type is incrementable, and pre- and post- operator-- for the type have common meaning.

  2. Specifies that a type is both _[decrementable](iterator.html#decrementable)_ and totally_ordered, and operator+=, operator-=, operator+, and operator- among the type and its different type have common meaning.

/*iterator*/ models

However, it only satisfies LegacyInputIterator if W models incrementable, and does not satisfy LegacyInputIterator otherwise.

Contents

[edit] Semantic requirements

  1. Type I models _decrementable_ only if I satisfies _decrementable_ and all concepts it subsumes are modeled, and given equal objects a and b of type I:
  1. Let D denote /*iota-diff-t*/<I>. Type I models _[advanceable](iterator.html#advanceable)_ only if I satisfies _[advanceable](iterator.html#advanceable)_ and all concepts it subsumes are modeled, and given

such that b is reachable from a after n applications of ++a, all following conditions are satisfied:

[edit] Nested types

[edit] Determining the iterator concept

iterator_concept is defined as follows:

[edit] Data members

Member Definition
W value_ the current value(exposition-only member object*)

[edit] Member functions

std::ranges::iota_view::iterator::iterator

| | (1) | (since C++20) | | | --------------------------------------------- | ------------- | ------------- | | constexpr explicit /*iterator*/( W value ); | (2) | (since C++20) |

  1. Value initializes _[value](iterator.html#value)_.

  2. Initializes _[value](iterator.html#value)_ with value.

std::ranges::iota_view::iterator::operator*

Returns _[value](iterator.html#value)_.

Example

#include #include   int main() { auto it{std::views::iota(6, 9).begin()}; const int& r = *it; // binds with temporary assert(*it == 6 and r == 6); ++it; assert(*it == 7 and r == 6); }

std::ranges::iota_view::iterator::operator++

constexpr /*iterator*/& operator++(); (1) (since C++20)
constexpr void operator++(int); (2) (since C++20)
constexpr /*iterator*/ operator++(int) requires std::incrementable<W>; (3) (since C++20)
  1. Equivalent to ++_[value](iterator.html#value)_ ; return *this;.

  2. Equivalent to ++_[value](iterator.html#value)_ ;.

  3. Equivalent to auto tmp = *this; ++_[value](iterator.html#value)_ ; return tmp;.

Example

std::ranges::iota_view::iterator::operator--

constexpr /*iterator*/& operator--() requires /*decrementable*/<W>; (1) (since C++20)
constexpr /*iterator*/operator--(int) requires /*decrementable*/<W>; (2) (since C++20)
  1. Equivalent to --_[value](iterator.html#value)_ ; return *this;.

  2. Equivalent to auto tmp = *this; --_[value](iterator.html#value)_ ; return tmp;.

Example

std::ranges::iota_view::iterator::operator+=

| constexpr /*iterator*/& operator+=( difference_type n ) requires /*advanceable*/<W>; | | (since C++20) | | ------------------------------------------------------------------------------------------- | | ------------- |

Updates _[value](iterator.html#value)_ and returns *this:

Example

#include #include   int main() { auto it{std::views::iota(5).begin()}; assert(it == 5); assert((it += 3) == 8); }

std::ranges::iota_view::iterator::operator-=

| constexpr /*iterator*/& operator-=( difference_type n ) requires /*advanceable*/<W>; | | (since C++20) | | -------------------------------------------------------------------------------------------- | | ------------- |

Updates _[value](iterator.html#value)_ and returns *this:

Example

#include #include   int main() { auto it{std::views::iota(6).begin()}; assert(it == 6); assert((it -= -3) == 9); }

std::ranges::iota_view::iterator::operator[]

| constexpr W operator[]( difference_type n ) const requires /*advanceable*/<W>; | | (since C++20) | | ------------------------------------------------------------------------------------ | | ------------- |

Returns W(_[value](iterator.html#value)_ + n).

Example

#include #include   int main() { auto it{std::views::iota(6).begin()}; assert(it == 6); assert((it + 3) == 9); }

[edit] Non-member functions

operator==, <, >, <=, >=, <=>(std::ranges::iota_view::iterator)

friend constexpr bool operator== ( const /*iterator*/& x, const /*iterator*/& y ) requires std::equality_comparable<W>; (1) (since C++20)
friend constexpr bool operator< ( const /*iterator*/& x, const /*iterator*/& y ) requires std::totally_ordered<W>; (2) (since C++20)
friend constexpr bool operator> ( const /*iterator*/& x, const /*iterator*/& y ) requires std::totally_ordered<W>; (3) (since C++20)
friend constexpr bool operator<= ( const /*iterator*/& x, const /*iterator*/& y ) requires std::totally_ordered<W>; (4) (since C++20)
friend constexpr bool operator>= ( const /*iterator*/& x, const /*iterator*/& y ) requires std::totally_ordered<W>; (5) (since C++20)
friend constexpr bool operator<=> ( const /*iterator*/& x, const /*iterator*/& y ) requires std::totally_ordered<W> && std::three_way_comparable<W>; (6) (since C++20)
  1. Returns y < x.

  2. Returns !(y < x).

  3. Returns !(x < y).

The != operator is synthesized from operator==.

These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when iterator is an associated class of the arguments.

operator+(std::ranges::iota_view::iterator)

friend constexpr /*iterator*/ operator+ ( /*iterator*/ i, difference_type n ) requires /*advanceable*/<W>; (1) (since C++20)
friend constexpr /*iterator*/ operator+ ( difference_type n, /*iterator*/ i ) requires /*advanceable*/<W>; (2) (since C++20)

Equivalent to i += n; return i;.

These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when iterator is an associated class of the arguments.

operator-(std::ranges::iota_view::iterator)

friend constexpr /*iterator*/ operator- ( /*iterator*/ i, difference_type n ) requires /*advanceable*/<W>; (1) (since C++20)
friend constexpr difference_type operator- ( const /*iterator*/& x, const /*iterator*/& y ) requires /*advanceable*/<W>; (2) (since C++20)
  1. Equivalent to i -= n; return i;.

  2. Let D be difference_type:

These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when iterator is an associated class of the arguments.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
P2259R1 C++20 member iterator_category is always defined defined only if W satisfies incrementable
LWG 3580 C++20 bodies of operator+ and operator- rule out implicit move made suitable for implicit move