Namespaces
Variants

std:: strong_order

From cppreference.net
Utilities library
定义于头文件 <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 的结果。

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_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 )

示例

另请参阅

支持全部6种运算符且可替换的三路比较结果类型
(类)
(C++20)
执行三路比较并生成 std::weak_ordering 类型的结果
(定制点对象)
执行三路比较并生成 std::partial_ordering 类型的结果
(定制点对象)
执行三路比较并生成 std::strong_ordering 类型的结果,即使 operator <=> 不可用
(定制点对象)