std::ranges::iota_view<W, Bound>::iterator - cppreference.com
From cppreference.com
|
(1) | (exposition only*) |
| Helper alias templates |
||
|
(2) | (exposition only*) |
| Helper concepts |
||
|
(3) | (exposition only*) |
|
(4) | (exposition only*) |
1) ranges::iota_view<W, Bound>::iterator is the type of the iterators returned by begin() and end() of ranges::iota_view<W, Bound>.
2) Calculates the difference type for both iterator types and integer-like types.
- If
Iis 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 ofIif such a type exists. - Otherwise,
Iis 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_incrementablein this case.
3) Specifies that a type is incrementable, and pre- and post- operator-- for the type have common meaning.
4) 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.
/*iterator*/ models
random_access_iteratorifWmodelsadvanceable(4),bidirectional_iteratorifWmodelsdecrementable(3),forward_iteratorifWmodelsincrementable, andinput_iteratorotherwise.
However, it only satisfies LegacyInputIterator if W models incrementable, and does not satisfy LegacyInputIterator otherwise.
Semantic requirements
3) 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:
- If
aandbare 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
aandbare in the domain of both pre- and post-operator++(i.e. they are incrementable), thenbool(--(++a) == b)istrue.
4) Let 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
aandbof typeIand - value
nof 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
xandyof 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.
Nested types
| Type | Definition |
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>
|
Determining the iterator concept
iterator_concept is defined as follows:
- If
Wmodelsadvanceable,iterator_conceptdenotes std::random_access_iterator_tag. - Otherwise, if
Wmodelsdecrementable,iterator_conceptdenotes std::bidirectional_iterator_tag. - Otherwise, if
Wmodelsincrementable,iterator_conceptdenotes std::forward_iterator_tag. - Otherwise,
iterator_conceptdenotes std::input_iterator_tag.
Data members
| Member | Definition |
W value_
|
the current value (exposition-only member object*) |
Member functions
std::ranges::iota_view::iterator::iterator
|
|
(1) | (since C++20) |
|
|
(2) | (since C++20) |
1) Value initializes value_.
2) Initializes value_ with value.
std::ranges::iota_view::iterator::operator*
|
|
(since C++20) | |
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++
|
|
(1) | (since C++20) |
|
|
(2) | (since C++20) |
|
|
(3) | (since C++20) |
1) Equivalent to ++value_ ; return *this;.
2) Equivalent to ++value_ ;.
3) Equivalent to auto tmp = *this; ++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--
|
|
(1) | (since C++20) |
|
|
(2) | (since C++20) |
1) Equivalent to --value_ ; return *this;.
2) Equivalent to auto tmp = *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+=
|
|
(since C++20) | |
Updates value_ and returns *this:
- If
Wis an unsigned-integer-like type: - Otherwise, performs
value_+= n.
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-=
|
|
(since C++20) | |
Updates value_ and returns *this:
- If
Wis an unsigned-integer-like type: - Otherwise, performs
value_-= n.
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[]
|
|
(since C++20) | |
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);
}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) |
1) Returns x.value_ == y.value_.
2) Returns x.value_ < y.value_.
3) Returns y < x.
4) Returns !(y < x).
5) Returns !(x < y).
6) Returns 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) |
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.
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 |