On this page
std::ranges::iota_view<W, Bound>::iterator
|
(1) | (since C++20) (exposition only*) |
Helper alias templates | ||
|
(2) | (exposition only*) |
Helper concepts | ||
|
(3) | (exposition only*) |
|
(4) | (exposition only*) |
iota_view::begin
.
/*iota-diff-t*/
calculates the difference type for both iterator types and integer-like types.
- If
W
is not an integral type, or if it is an integral type andsizeof(std::iter_difference_t<I>)
is greater thansizeof(I)
, then/*iota-diff-t*/<I>
isstd::iter_difference_t<I>
. - Otherwise,
/*iota-diff-t*/<I>
is a signed integer type of width greater than the width ofI
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.
decrementable
specifies that a type is incrementable
, and pre- and post- operator--
for the type have common meaning.
advanceable
specifies that a type is both decrementable
and totally_ordered
, and operator+=
, operator-=
, operator+
, and operator-
among the type and its different type have common meaning.
Semantic requirements
3) TypeI
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
andb
are in the domain of both pre- and post-operator--
(i.e. they are decrementable), then the following are alltrue
:std::addressof(--a) == std::addressof(a)
,bool(a-- == b)
,bool(((void)a--, a) == --b)
,bool(++(--a) == b)
.
- If
a
andb
are in the domain of both pre- and post-operator++
(i.e. they are incrementable), thenbool(--(++a) == b)
istrue
.
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
andb
of typeI
and - value
n
of typeD
,
such that b
is reachable from a
after n
applications of ++a
, all following conditions are satisfied:
(a += n)
is equal tob
.std::addressof(a += n)
is equal tostd::addressof(a)
.I(a + n)
is equal to(a += n)
.- For any two positive values
x
andy
of typeD
, ifI(a + D(x + y))
is well-defined, thenI(a + D(x + y))
is equal toI(I(a + x) + y)
. I(a + D(0))
is equal toa
.- If
I(a + D(n - 1))
is well-defined, thenI(a + n)
is equal to[](I c) { return ++c; }(I(a + D(n - 1)))
. (b += -n)
is equal toa
.(b -= n)
is equal toa
.std::addressof(b -= n)
is equal tostd::addressof(b)
.I(b - n)
is equal to(b -= n)
.D(b - a)
is equal ton
.D(a - b)
is equal toD(-n)
.bool(a <= b)
istrue
.
Member types
Member type | Definition |
---|---|
iterator_concept |
|
iterator_category |
std::input_iterator_tag if W models incrementable .Otherwise, there is no member type iterator_category . |
value_type |
W |
difference_type |
/*iota-diff-t*/<W> |
Notes: /*iterator*/
is
random_access_iterator
ifW
modelsadvanceable
,bidirectional_iterator
ifW
modelsdecrementable
,forward_iterator
ifW
modelsincrementable
, andinput_iterator
otherwise.
However, it only satisfies LegacyInputIterator if W
models incrementable
, and does not satisfy LegacyInputIterator otherwise.
Data members
Member name | Definition |
---|---|
value_ (private) |
The value of type W used for dereferencing.(exposition-only member object*) |
Member functions
std::ranges::iota_view::iterator::iterator
|
(1) | (since C++20) |
|
(2) | (since C++20) |
value_
via its default member initializer (= W()
).
value_
with value
. This value will be returned by operator*
and incremented by operator++
.
std::ranges::iota_view::iterator::operator*
|
(since C++20) |
Returns the current value, by value (in other words, this is a read-only view).
std::ranges::iota_view::iterator::operator++
|
(1) | (since C++20) |
|
(2) | (since C++20) |
|
(3) | (since C++20) |
++value_; return *this;
.
++value_;
.
auto tmp = *this; ++value_; return tmp;
.
std::ranges::iota_view::iterator::operator--
|
(1) | (since C++20) |
|
(2) | (since C++20) |
--value_; return *this;
.
auto tmp = *this; --value_; return tmp;
.
std::ranges::iota_view::iterator::operator+=
|
(since C++20) |
If W
is unsigned-integer-like, performs value_ += static_cast<W>(n)
if n
is non-negative, value -= static_cast<W>(-n)
otherwise, and then returns *this
.
Otherwise, equivalent to value_ += n; return *this;
.
std::ranges::iota_view::iterator::operator-=
|
(since C++20) |
If W
is unsigned-integer-like, performs value_ -= static_cast<W>(n)
if n
is non-negative, or value += static_cast<W>(-n)
otherwise, and then returns *this
.
Otherwise, equivalent to value_ -= n; return *this;
.
std::ranges::iota_view::iterator::operator[]
|
(since C++20) |
Equivalent to return W(value_ + n);
.
Non-member functions
operator==, <, >, <=, >=, <=>(std::ranges::iota_view::iterator)
|
(1) | (since C++20) |
|
(2) | (since C++20) |
|
(3) | (since C++20) |
|
(4) | (since C++20) |
|
(5) | (since C++20) |
|
(6) | (since C++20) |
return x.value_ == y.value_;
.
return x.value_ < y.value_;
.
return y < x;
.
return !(y < x);
.
return !(x < y);
.
return x.value_ <=> y.value_;
.
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)
|
(1) | (since C++20) |
|
(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)
|
(1) | (since C++20) |
|
(2) | (since C++20) |
i -= n; return i;
.
D
be difference_type
.
- If
W
is signed-integer-like, equivalent toreturn D(D(x.value_) - D(y.value_));
. - Otherwise, if
W
is unsigned-integer-like, equivalent toreturn y.value_ > x.value_ ? D(-D(y.value_ - x.value_)) : D(x.value_ - y.value_);
. - Otherwise, equivalent to
return x.value_ - y.value_;
.
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.
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 |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/iota_view/iterator