| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <iterator> | ||
| (1) | ||
template<std::indirectly_readable I, std::indirectly_regular_unary_invocable<I> Proj> | (since C++20) (until C++26) | |
template<std::indirectly_readable I, std::indirectly_regular_unary_invocable<I> Proj> | (since C++26) | |
template<std::weakly_incrementable I,class Proj> struct incrementable_traits<std::projected<I, Proj>> | (2) | (since C++20) (until C++26) |
Helper templates | ||
template<class I,class Proj> struct/*projected-impl*/ | (3) | (since C++26) (exposition only*) |
projected combines anindirectly_readable typeI and a callable object typeProj into a newindirectly_readable type whose reference type is the result of applyingProj to thestd::iter_reference_t<I>.weakly_incrementable type whenI is also aweakly_incrementable type.difference_type exists only ifI modelsweakly_incrementable.projected is used only to constrain algorithms that accept callable objects and projections, and hence itsoperator*() is not defined.
Contents |
| I | - | an indirectly readable type |
| Proj | - | projection applied to a dereferencedI |
The indirect layer preventsI andProj to be associated classes ofprojected. When an associated class ofI orProj is an incomplete class type, the indirect layer avoids the unnecessary attempt to inspect the definition of that type that results in hard error.
#include <algorithm>#include <cassert>#include <functional>#include <iterator> template<class T>struct Holder{ T t;}; struct Incomplete; using P= Holder<Incomplete>*; static_assert(std::equality_comparable<P>);// OKstatic_assert(std::indirectly_comparable<P*, P*,std::equal_to<>>);// Error before C++26static_assert(std::sortable<P*>);// Error before C++26 int main(){ P a[10]={};// ten null pointersassert(std::count(a, a+10, nullptr)==10);// OKassert(std::ranges::count(a, a+10, nullptr)==10);// Error before C++26}
(C++26) | computes the value type of anindirectly_readable type by projection(alias template)[edit] |