Helper templates
(3) (since C++26)template
projected
combines an
indirectly_readable
type
I
and a callable object type
Proj
into a new
indirectly_readable
type whose reference type is the result of applying
Proj
to the
std::iter_reference_t<I>.
For the exposition-only nested class
/*type*/, the nested type
difference_type
exists only if
I
models
weakly_incrementable
.
projected
is used only to constrain algorithms that accept callable objects and projections, and hence its operator*() is not defined.
I
[edit] Notes
The indirect layer prevents I
and Proj
to be associated classes of projected
. When an associated class of I
or Proj
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>); // OK static_assert(std::indirectly_comparable<P*, P*, std::equal_to<>>); // Error before C++26 static_assert(std::sortable<P*>); // Error before C++26 int main() { P a[10] = {}; // ten null pointers assert(std::count(a, a + 10, nullptr) == 10); // OK assert(std::ranges::count(a, a + 10, nullptr) == 10); // Error before C++26 }[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4