std::totally_ordered, std::totally_ordered_with
| 定義於標頭檔案 <concepts> |
||
| template< class T > concept totally_ordered = |
(1) | (C++20 起) |
| template< class T, class U > concept totally_ordered_with = |
(2) | (C++20 起) |
| 輔助概念 |
||
| template< class T, class U > concept __PartiallyOrderedWith = |
(3) | (僅作說明*) |
std::totally_ordered_with 指定 (可能混合的) T 和 U 運算元上的比較運算子 ==,!=,<,>,<=,>= 的結果與嚴格全序一致。比較混合運算元會產生與比較轉換為其共同型別的運算元等效的結果。__PartiallyOrderedWith 指定型別為 T 的值和型別為 U 的值可以使用 <, >, <= 和 >= 互相進行偏序比較 (以任一順序),並且比較結果是一致的。目錄 |
[編輯] 語義要求
這些概念僅當它們被滿足並且它們所包含的所有概念都被建模時才被建模。
a、b 和 c 時,以下條件成立:- bool(a < b), bool(a > b) 和 bool(a == b) 中恰好有一個為 true;
- 如果 bool(a < b) 和 bool(b < c) 都為 true,則 bool(a < c) 為 true;
- bool(a > b) == bool(b < a)
- bool(a >= b) == !bool(a < b)
- bool(a <= b) == !bool(b < a)
-
t和t2,表示型別分別為 const std::remove_reference_t<T> 和 std::remove_reference_t<T> 的不同等價物件,以及 -
u和u2,表示型別分別為 const std::remove_reference_t<U> 和 std::remove_reference_t<U> 的不同等價物件,
令 C 為 std::common_reference_t<const std::remove_reference_t<T>&, const std::remove_reference_t<U>&>,並且,給定表示式 E 和型別 C,令 CONVERT_TO<C>(E) 為
|
(直至 C++23) |
|
(C++23 起) |
以下條件為真
- bool(t < u) == bool(CONVERT_TO<C>(t2) < CONVERT_TO<C>(u2))
- bool(t > u) == bool(CONVERT_TO<C>(t2) > CONVERT_TO<C>(u2))
- bool(t <= u) == bool(CONVERT_TO<C>(t2) <= CONVERT_TO<C>(u2))
- bool(t >= u) == bool(CONVERT_TO<C>(t2) >= CONVERT_TO<C>(u2))
- bool(u < t) == bool(CONVERT_TO<C>(u2) < CONVERT_TO<C>(t2))
- bool(u > t) == bool(CONVERT_TO<C>(u2) > CONVERT_TO<C>(t2))
- bool(u <= t) == bool(CONVERT_TO<C>(u2) <= CONVERT_TO<C>(t2))
- bool(u >= t) == bool(CONVERT_TO<C>(u2) >= CONVERT_TO<C>(t2))
- 任何型別為 const std::remove_reference_t<T> 的左值
t,以及 - 任何型別為 const std::remove_reference_t<U> 的左值
u,
以下條件為真
- t < u, t <= u, t > u, t >= u, u < t, u <= t, u > t 和 u >= t 擁有相同的域;
- bool(t < u) == bool(u > t);
- bool(u < t) == bool(t > u);
- bool(t <= u) == bool(u >= t);以及
- bool(u <= t) == bool(t >= u).
[編輯] 相等性保持
標準庫概念的 requires 表示式 中宣告的表示式需要 保持相等性(除非另有說明)。
[編輯] 隱式表示式變體
一個 requires 表示式 如果使用了對於某些常量左值運算元而言是非修改性的表示式,則也需要 隱式表示式變體。
[編輯] 參考資料
- C++23 標準 (ISO/IEC 14882:2024)
- 18.5.5 概念
totally_ordered[concept.totallyordered]
- 18.5.5 概念
- C++20 標準 (ISO/IEC 14882:2020)
- 18.5.4 概念
totally_ordered[concept.totallyordered]
- 18.5.4 概念
[編輯] 另請參閱
| 指定運算子 <=> 在給定型別上產生一致的結果 (概念) |