std::strong_order

来自cppreference.com
< cpp‎ | utility
 
 
 
在标头 <compare> 定义
inline namespace /* 未指定 */ {

    inline constexpr /* 未指定 */ strong_order = /* 未指定 */;

}
(C++20 起)
调用签名
template< class T, class U >

    requires /* 见下文 */

constexpr std::strong_ordering strong_order(T&& t, U&& u) noexcept(/* 见下文 */);

用三路比较比较两个值,并产生 std::strong_ordering 类型的结果。

tu 为表达式,而 TU 分别代表 decltype((t))decltype((u)),那么 std::strong_order(t, u) 表达式等价于:

目录

定制点对象

名字 std::strong_order 代表一个定制点对象,它是某个字面 semiregular 类类型的 const 函数对象。 细节参见定制点对象 (CustomizationPointObject)

[编辑] IEEE 浮点类型的严格全序

xy 为相同 IEEE 浮点类型的值,而 total_order_less(x, y) 为指示在 ISO/IEC/IEEE 60559 中的 totalOrder 所定义的严格全序中 x 是否前趋于 y 的布尔结果。

当且仅当 xy 拥有同一位模式时,total_order_less(x, y) || total_order_less(y, x) == false

  • 如果 xy 都不是 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)(仅对十进制浮点数有意义);
  • 如果 xy 是 NaN:
    • 如果 x 是负 NaN 且 y 不是负 NaN,那么 total_order_less(x, y) == true
    • 如果 x 不是正 NaN 且 y 是正 NaN,那么 total_order_less(x, y) == true
    • 如果 xy 都是拥有相同符号的 NaN 且 x 的尾数域小于 y 的,那么 total_order_less(x, y) == !std::signbit(x)

[编辑] 示例

[编辑] 参阅

三路比较的结果类型,支持所有 6 种运算符且可替换
(类) [编辑]
进行三路比较并产生 std::weak_ordering 类型的结果
(定制点对象) [编辑]
进行三路比较并产生 std::partial_ordering 类型的结果
(定制点对象) [编辑]
进行三路比较并产生 std::strong_ordering 类型的结果,即使 operator<=> 不可用
(定制点对象) [编辑]