std::ranges::iota_view<W, Bound>::iterator
using /*iota-diff-t*/ = /* see below */;
concept /*decrementable*/ =
std::incrementable <I> && requires(I i) {
{ --i } -> std::same_as <I&>;
{ i-- } -> std::same_as <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>>;
iterator
is the type of the iterators returned by begin()
and end()
of ranges::iota_view <W, Bound>.- If
I
is not an integral type, or if it is an integral type and sizeof(std::iter_difference_t <I>) is greater than sizeof(I), then /*iota-diff-t*/<I> is std::iter_difference_t <I>. - Otherwise, /*iota-diff-t*/<I> is a signed integer type of width greater than the width of
I
if such a type exists. - Otherwise,
I
is one of the widest integral types, and /*iota-diff-t*/<I> is an unspecified signed-integer-like type of width not less than the width ofI
. It is unspecified whether /*iota-diff-t*/<I> modelsweakly_incrementable
in this case.
incrementable
, and pre- and post- operator-- for the type have common meaning.decrementable
and totally_ordered
, and operator+=, operator-=, operator+, and operator- among the type and its different type have common meaning./*iterator*/ models
-
random_access_iterator
if W modelsadvanceable
(4), -
bidirectional_iterator
if W modelsdecrementable
(3), -
forward_iterator
if W modelsincrementable
, and -
input_iterator
otherwise.
However, it only satisfies LegacyInputIterator if W
models incrementable
, and does not satisfy LegacyInputIterator otherwise.
Contents
- 1 Semantic requirements
- 2 Nested types
- 3 Data members
- 4 Member functions
- 5 std::ranges::iota_view::iterator::iterator
- 6 std::ranges::iota_view::iterator::operator*
- 7 std::ranges::iota_view::iterator::operator++
- 8 std::ranges::iota_view::iterator::operator--
- 9 std::ranges::iota_view::iterator::operator+=
- 10 std::ranges::iota_view::iterator::operator-=
- 11 std::ranges::iota_view::iterator::operator[]
- 12 operator==, <, >, <=, >=, <=>(std::ranges::iota_view::iterator)
- 13 operator+(std::ranges::iota_view::iterator)
- 14 operator-(std::ranges::iota_view::iterator)
[edit] Semantic requirements
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
:
- If a and b are in the domain of both pre- and post- operator-- (i.e. they are decrementable), then the following are all true:
- std::addressof (--a) == std::addressof (a),
- bool(a-- == b),
- bool(((void)a--, a) == --b),
- bool(++(--a) == b).
- If a and b are in the domain of both pre- and post- operator++ (i.e. they are incrementable), then bool(--(++a) == b) is true.
D
denote /*iota-diff-t*/<I>. Type I
models advanceable
only if I
satisfies advanceable
and all concepts it subsumes are modeled, and given
- objects a and b of type
I
and - value n of type
D
,
such that b is reachable from a after n applications of ++a, all following conditions are satisfied:
- (a += n) is equal to b.
- std::addressof (a += n) is equal to std::addressof (a).
- I(a + n) is equal to (a += n).
- For any two positive values x and y of type
D
, if I(a + D(x + y)) is well-defined, then I(a + D(x + y)) is equal to I(I(a + x) + y). - I(a + D(0)) is equal to a.
- If I(a + D(n - 1)) is well-defined, then I(a + n) is equal to [](I c) { return ++c; }(I(a + D(n - 1))).
- (b += -n) is equal to a.
- (b -= n) is equal to a.
- std::addressof (b -= n) is equal to std::addressof (b).
- I(b - n) is equal to (b -= n).
- D(b - a) is equal to n.
- D(a - b) is equal to D(-n).
- bool(a <= b) is true.
[edit] Nested types
iterator_concept
an iterator tag, see below
iterator_category
(only present if
W
models incrementable
and/*iota-diff-t*/<W> is an integral type) std::input_iterator_tag
value_type
W
difference_type
/*iota-diff-t*/<W>
[edit] Determining the iterator concept
iterator_concept
is defined as follows:
- If
W
modelsadvanceable
,iterator_concept
denotes std::random_access_iterator_tag . - Otherwise, if
W
modelsdecrementable
,iterator_concept
denotes std::bidirectional_iterator_tag . - Otherwise, if
W
modelsincrementable
,iterator_concept
denotes std::forward_iterator_tag . - Otherwise,
iterator_concept
denotes std::input_iterator_tag .
[edit] Data members
W
value_
the current value(exposition-only member object*)
[edit] Member functions
std::ranges::iota_view::iterator::iterator
value_
.std::ranges::iota_view::iterator::operator*
noexcept(std::is_nothrow_copy_constructible_v <W>);
Returns value_
.
Example
#include <cassert> #include <ranges> 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++
value_
; return *this;.value_
;.value_
; return tmp;.Example
#include <cassert> #include <ranges> int main() { auto it{std::views::iota (8).begin()}; assert (*it == 8); assert (*++it == 9); assert (*it++ == 9); assert (*it == 10); }
std::ranges::iota_view::iterator::operator--
value_
; return *this;.value_
; return tmp;.Example
#include <cassert> #include <ranges> int main() { auto it{std::views::iota (8).begin()}; assert (*it == 8); assert (*--it == 7); assert (*it-- == 7); assert (*it == 6); }
std::ranges::iota_view::iterator::operator+=
requires /*advanceable*/<W>;
Updates value_
and returns *this:
- If
W
is an unsigned-integer-like type: - Otherwise, performs
value_
Example
#include <cassert> #include <ranges> int main() { auto it{std::views::iota (5).begin()}; assert (*it == 5); assert (*(it += 3) == 8); }
std::ranges::iota_view::iterator::operator-=
requires /*advanceable*/<W>;
Updates value_
and returns *this:
- If
W
is an unsigned-integer-like type: - Otherwise, performs
value_
Example
#include <cassert> #include <ranges> int main() { auto it{std::views::iota (6).begin()}; assert (*it == 6); assert (*(it -= -3) == 9); }
std::ranges::iota_view::iterator::operator[]
requires /*advanceable*/<W>;
Returns W(value_
+ n).
Example
#include <cassert> #include <ranges> 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)
( const /*iterator*/& x, const /*iterator*/& y )
( const /*iterator*/& x, const /*iterator*/& y )
( const /*iterator*/& x, const /*iterator*/& y )
( const /*iterator*/& x, const /*iterator*/& y )
( const /*iterator*/& x, const /*iterator*/& y )
( const /*iterator*/& x, const /*iterator*/& 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)
( /*iterator*/ i, difference_type n )
( difference_type n, /*iterator*/ i )
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)
( /*iterator*/ i, difference_type n )
( const /*iterator*/& x, const /*iterator*/& y )
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 |