Namespaces
Variants

std:: weak_order

From cppreference.net
Utilities library
定义于头文件 <compare>
inline namespace /* 未指定 */ {

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

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

requires /* 见下文 */

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

使用三路比较法比较两个值,并生成类型为 std::weak_ordering 的结果。

t u 为表达式,且 T U 分别表示 decltype ( ( t ) ) decltype ( ( u ) ) ,则 std :: weak_order ( t, u ) 表达式等价性 上等同于:

目录

定制点对象

名称 std::weak_order 表示一个 定制点对象 ,这是一个字面量 semiregular 类类型的常量 函数对象 。详细信息请参阅 定制点对象

IEEE浮点类型的严格弱序

x y 为相同 IEEE 浮点类型的值,且 weak_order_less ( x, y ) 为布尔结果,指示在 C++ 标准定义的严格弱序中 x 是否先于 y

  • 如果 x y 均非 NaN,则 weak_order_less ( x, y ) == true 当且仅当 x < y ,即所有相等浮点数值的表示形式均等价;
  • 如果 x 为负 NaN 且 y 非负 NaN,则 weak_order_less ( x, y ) == true
  • 如果 x 非正 NaN 且 y 为正 NaN,则 weak_order_less ( x, y ) == true
  • 如果 x y 均为同号 NaN,则 ( weak_order_less ( x, y ) || weak_order_less ( y, x ) ) == false ,即所有同号 NaN 均等价。

示例

参见

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