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 概念
[编辑] 另请参阅
指定运算符 <=> 在给定类型上产生一致的结果 (概念) |