std::strong_order
| 定义于头文件 <compare>
|
||
inline namespace /* unspecified */ {
inline constexpr /* unspecified */ strong_order = /* unspecified */;
}
|
(C++20 起) | |
| 调用签名 |
||
template< class T, class U >
requires /* see below */
constexpr std::strong_ordering strong_order( T&& t, U&& u ) noexcept(/* see below */);
|
||
使用三路比较比较两个值,并产生类型为 std::strong_ordering 的结果。
设 t 和 u 为表达式,T 和 U 分别表示 decltype((t)) 和 decltype((u)),则 std::strong_order(t, u) 是表达式等价于:
- 如果
std::is_same_v<std::decay_t<T>, std::decay_t<U>>为true:std::strong_ordering(strong_order(t, u)),且它是在不包含std::strong_order声明的语境中执行重载决议的良构表达式,- 否则,如果
T是浮点类型:- 若
std::numeric_limits<T>::is_iec559为true,则执行 ISO/IEC/IEEE 60559 totalOrder 浮点值比较,并将该结果作为类型 std::strong_ordering 的值返回(注意:此比较能区分正零与负零,以及不同表示的 NaN), - 否则,产生类型为 std::strong_ordering 的值,该值与
T的比较运算符所观察到的顺序一致,
- 若
- 否则,若
std::strong_ordering(std::compare_three_way()(t, u))良构,则使用之。
- 在其他所有情况下,该表达式为病式,当它出现在模板实例化的立即语境中时,可能导致替换失败。
定制点对象
名称
std::strong_order
表示一个
定制点对象
,它是一个字面量
semiregular
类类型的常量
函数对象
。详细信息请参阅
定制点对象
。
IEEE浮点类型的严格全序
设 x 和 y 为相同 IEEE 浮点类型的值,且 total_order_less ( x, y ) 为布尔结果,指示 x 是否在 ISO/IEC/IEEE 60559 中 totalOrder 定义的严格全序中先于 y 。
( total_order_less ( x, y ) || total_order_less ( y, x ) ) == false 当且仅当 x 与 y 具有相同的位模式。
-
若
x
与
y
均非 NaN:
- 若 x < y ,则 total_order_less ( x, y ) == true ;
- 若 x > y ,则 total_order_less ( x, y ) == false ;
-
若
x
==
y
:
- 若 x 为负零且 y 为正零,则 total_order_less ( x, y ) == true ;
- 若 x 非零且 x 的指数域小于 y 的指数域,则 total_order_less ( x, y ) == ( x > 0 ) (仅对十进制浮点数有意义);
-
若
x
或
y
为 NaN:
- 若 x 为负 NaN 且 y 非负 NaN,则 total_order_less ( x, y ) == true ;
- 若 x 非正 NaN 且 y 为正 NaN,则 total_order_less ( x, y ) == true ;
- 若 x 与 y 为同号 NaN 且 x 的尾数域小于 y 的尾数域,则 total_order_less ( x, y ) == ! std:: signbit ( x ) 。
示例
|
本节内容不完整
原因:缺少示例 |
另请参阅
|
(C++20)
|
支持全部6种运算符且可替换的三路比较结果类型
(类) |
|
(C++20)
|
执行三路比较并生成
std::weak_ordering
类型的结果
(定制点对象) |
|
(C++20)
|
执行三路比较并生成
std::partial_ordering
类型的结果
(定制点对象) |
|
(C++20)
|
执行三路比较并生成
std::strong_ordering
类型的结果,即使
operator
<=>
不可用
(定制点对象) |