| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
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*/= | (3) | (exposition only*) |
template<class I> concept/*advanceable*/= | (4) | (exposition only*) |
iterator is the type of the iterators returned bybegin() andend() ofranges::iota_view<W, Bound>.I 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>.I if such a type exists.I is one of the widest integral types, and/*iota-diff-t*/<I> is an unspecifiedsigned-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 andtotally_ordered, andoperator+=,operator-=,operator+, andoperator- among the type and its different type have common meaning./*iterator*/ models
random_access_iterator ifW modelsadvanceable(4),bidirectional_iterator ifW modelsdecrementable(3),forward_iterator ifW modelsincrementable, andinput_iterator otherwise.However, it only satisfiesLegacyInputIterator ifW modelsincrementable, and does not satisfyLegacyInputIterator otherwise.
I modelsdecrementable only ifI satisfiesdecrementable and all concepts it subsumes are modeled, and given equal objectsa andb of typeI:D denote/*iota-diff-t*/<I>. TypeI modelsadvanceable only ifI satisfiesadvanceable and all concepts it subsumes are modeled, and givenI andD,such thatb is reachable froma aftern applications of++a, all following conditions are satisfied:
D, ifI(a+ D(x+ y)) is well-defined, thenI(a+ D(x+ y)) is equal toI(I(a+ x)+ y).| Type | Definition |
iterator_concept | aniterator tag, see below |
iterator_category(only present if W modelsincrementable and/*iota-diff-t*/<W> is an integral type) | std::input_iterator_tag |
value_type | W |
difference_type | /*iota-diff-t*/<W> |
iterator_concept is defined as follows:
W modelsadvanceable,iterator_concept denotesstd::random_access_iterator_tag.W modelsdecrementable,iterator_concept denotesstd::bidirectional_iterator_tag.W modelsincrementable,iterator_concept denotesstd::forward_iterator_tag.iterator_concept denotesstd::input_iterator_tag.| Member | Definition |
Wvalue_ | the current value (exposition-only member object*) |
/*iterator*/() requiresstd::default_initializable<W>=default; | (1) | (since C++20) |
constexprexplicit/*iterator*/( W value); | (2) | (since C++20) |
value_.constexpr W operator*()const noexcept(std::is_nothrow_copy_constructible_v<W>); | (since C++20) | |
Returnsvalue_.
#include <cassert>#include <ranges> int main(){auto it{std::views::iota(6,9).begin()};constint& r=*it;// binds with temporaryassert(*it==6 and r==6);++it;assert(*it==7 and r==6);}
constexpr/*iterator*/& operator++(); | (1) | (since C++20) |
constexprvoid operator++(int); | (2) | (since C++20) |
constexpr/*iterator*/ operator++(int) requiresstd::incrementable<W>; | (3) | (since C++20) |
value_ ;return*this;.value_ ;.value_ ;return tmp;.#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);}
constexpr/*iterator*/& operator--() requires/*decrementable*/<W>; | (1) | (since C++20) |
constexpr/*iterator*/operator--(int) requires/*decrementable*/<W>; | (2) | (since C++20) |
value_ ;return*this;.value_ ;return tmp;.#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);}
constexpr/*iterator*/& operator+=( difference_type n) requires/*advanceable*/<W>; | (since C++20) | |
Updatesvalue_ and returns*this:
W is anunsigned-integer-like type:value_ += n.#include <cassert>#include <ranges> int main(){auto it{std::views::iota(5).begin()};assert(*it==5);assert(*(it+=3)==8);}
constexpr/*iterator*/& operator-=( difference_type n) requires/*advanceable*/<W>; | (since C++20) | |
Updatesvalue_ and returns*this:
W is anunsigned-integer-like type:value_ -= n.#include <cassert>#include <ranges> int main(){auto it{std::views::iota(6).begin()};assert(*it==6);assert(*(it-=-3)==9);}
constexpr W operator[]( difference_type n)const requires/*advanceable*/<W>; | (since C++20) | |
ReturnsW(value_ + n).
#include <cassert>#include <ranges> int main(){auto it{std::views::iota(6).begin()};assert(*it==6);assert(*(it+3)==9);}
friendconstexprbool operator== (const/*iterator*/& x,const/*iterator*/& y) | (1) | (since C++20) |
friendconstexprbool operator< (const/*iterator*/& x,const/*iterator*/& y) | (2) | (since C++20) |
friendconstexprbool operator> (const/*iterator*/& x,const/*iterator*/& y) | (3) | (since C++20) |
friendconstexprbool operator<= (const/*iterator*/& x,const/*iterator*/& y) | (4) | (since C++20) |
friendconstexprbool operator>= (const/*iterator*/& x,const/*iterator*/& y) | (5) | (since C++20) |
friendconstexprbool operator<=> (const/*iterator*/& x,const/*iterator*/& y) | (6) | (since C++20) |
The!= operator issynthesized fromoperator==.
These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.
friendconstexpr/*iterator*/ operator+ (/*iterator*/ i, difference_type n) | (1) | (since C++20) |
friendconstexpr/*iterator*/ operator+ ( difference_type n,/*iterator*/ i) | (2) | (since C++20) |
Equivalent toi+= n;return i;.
These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.
friendconstexpr/*iterator*/ operator- (/*iterator*/ i, difference_type n) | (1) | (since C++20) |
friendconstexpr difference_type operator- (const/*iterator*/& x,const/*iterator*/& y) | (2) | (since C++20) |
D bedifference_type:These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.
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 | memberiterator_category is always defined | defined only ifW satisfiesincrementable |
| LWG 3580 | C++20 | bodies ofoperator+ andoperator- rule outimplicit move | made suitable for implicit move |