std::projected
| 定义于头文件  <iterator> | ||
| (1) | ||
| template< std::indirectly_readable I,           std::indirectly_regular_unary_invocable<I> Proj > | (C++20 起) (直到 C++26) | |
| template< std::indirectly_readable I,           std::indirectly_regular_unary_invocable<I> Proj > | (C++26 起) | |
| template< std::weakly_incrementable I, class Proj > struct incrementable_traits<std::projected<I, Proj>> | (2) | (C++20 起) (直到 C++26) | 
| template< class I, class Proj > struct /*projected-impl*/ | (3) | (C++26 起) (仅作说明*) | 
I 也是 weakly_incrementable 类型时,成为 weakly_incrementable 类型。`projected` 仅用于约束接受可调用对象和投影的算法,因此其 operator*() 未定义。
| 目录 | 
[编辑] 模板参数
| I | - | 一个间接可读类型 | 
| Proj | - | 应用于解引用后的 I的投影 | 
[编辑] 注意
间接层阻止 `I` 和 `Proj` 成为 `projected` 的关联类。当 `I` 或 `Proj` 的关联类是一个不完整类类型时,间接层避免了不必要的尝试检查该类型的定义,这可能导致硬错误。
[编辑] 示例
#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 }
[编辑] 参阅
| (C++26) | 通过投影计算 indirectly_readable类型的值类型(别名模板) | 


