std::totally_ordered, std::totally_ordered_with
定义于头文件 <concepts> |
||
template< class T > 概念 totally_ordered = |
(1) | (自 C++20 起) |
template< class T, class U > 概念 totally_ordered_with = |
(2) | (自 C++20 起) |
辅助概念 |
||
template< class T, class U > 概念 __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 概念
[编辑] 参见
指定运算符 <=> 在给定类型上产生一致的结果 (概念) |