| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <iterator> | ||
std::indirectly_unary_invocable | ||
template<class F,class I> concept indirectly_unary_invocable= | (since C++20) | |
std::indirectly_regular_unary_invocable | ||
template<class F,class I> concept indirectly_regular_unary_invocable= | (since C++20) | |
The conceptsindirectly_unary_invocable andindirectly_regular_unary_invocable specify requirements for algorithms that call (regular) unary invocables as their arguments. The key difference between these concepts andstd::invocable is that they are applied to the type theI references, rather thanI itself.
The distinction betweenindirectly_unary_invocable andindirectly_regular_unary_invocable is purely semantic.
#include <algorithm>#include <iterator>#include <print>#include <ranges> struct IntWrapper{int i; explicit IntWrapper(int i): i(i){} IntWrapper(IntWrapper&&)=default; IntWrapper& operator=(IntWrapper&&)=default;}; int main(){auto ints= std::views::iota(1,10);auto print=[](IntWrapper w){std::print("{} ", w.i);};auto wrap=[](int i){return IntWrapper{i};}; using Proj= std::projected<decltype(ints.begin()), decltype(wrap)>; // error (evaluated to false) until P2609R3:// this was because 'std::iter_value_t<Proj> &' is the same as 'IntWrapper&'// which is not convertible to 'IntWrapper' (implicitly deleted copy ctor) static_assert(std::indirectly_unary_invocable<decltype(print), Proj>); // if the compile-time check above evaluates to true, then this is well-formed: std::ranges::for_each(ints, print, wrap);}
Output:
1 2 3 4 5 6 7 8 9
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P2609R3 | C++20 | some requirements were defined in terms ofstd::iter_value_t<I>& which mishandled projections resulting in incompatibility with invocableF& | defined in terms of/*indirect-value-t*/<I> to correctly handle such projections |
| P2997R1 | C++20 | corresponding concepts requiredF& to satisfyinvocable andregular_invocable, respectively, withstd::iter_common_reference_t<I> | does not require |