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 型別的值型別(別名模板) |