std::strong_order
| 在标头  <compare>定义 | ||
| inline namespace /* unspecified */ {     inline constexpr /* unspecified */ strong_order = /* unspecified */; | (C++20 起) | |
| 调用签名 | ||
| template< class T, class U >     requires /* 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 ),
-  否则,产生与 T的比较运算符所观察的顺序一致的 std::strong_ordering 类型值,
 
- 否则为 std::strong_ordering(std::compare_three_way()(t, u)) ,若它为良构。
 
-  std::strong_ordering(strong_order(t, u)) ,若在不包含 
- 所有其他情况下,表达式为非良构,这能在出现于模板实例化的立即语境时导致替换失败。
表达式等价
表达式 e 表达式等价于表达式 f ,若 e 与 f 拥有相同效果,均为潜在抛出或均非潜在抛出(即 noexcept(e) == noexcept(f) ),且均为常量子表达式或均非常量子表达式。
定制点对象
名字 std::strong_order 代表一个定制点对象,它是字面 semiregular 类类型的 const 函数对象。为说明目的,以 __strong_order_fn 表示其类型的 cv 无限定版本。
__strong_order_fn 的所有实例均相等。在相同参数上调用类型 __strong_order_fn 的不同实例的效果是等价的,无关乎指代该实例的表达式是左值还是右值,以及是否为 const 限定(然而不要求 volatile 限定的实例可调用)。从而能自由地复制 std::strong_order 并且能彼此替代地使用其副本。
给定类型集合 Args... ,若 std::declval<Args>()... 满足上面对于 std::strong_order 的参数要求,则 __strong_order_fn 实现
- std::invocable<__strong_order_fn, Args...>、
- std::invocable<const __strong_order_fn, Args...>、
- std::invocable<__strong_order_fn&, Args...> 及
- std::invocable<const __strong_order_fn&, Args...> 。
否则, __strong_order_fn 的函数调用运算符不参与重载决议。
注解
IEEE 浮点类型的严格全序
令 x 与 y 为相同 IEEE 浮点类型的值,而 total_order_less(x, y) 为指示在 ISO/IEC/IEEE 60559 中的 totalOrder 所定义的严格全序中 x 是否前趋于 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类型结果(定制点对象) | 
| 进行三路比较并产生 std::strong_ordering类型的结果,即使 operator<=> 不可用(定制点对象) |