std:: weak_order
|
定义于头文件
<compare>
|
||
|
inline
namespace
/* 未指定 */
{
inline
constexpr
/* 未指定 */
weak_order
=
/* 未指定 */
;
|
(C++20 起) | |
|
调用签名
|
||
|
template
<
class
T,
class
U
>
requires
/* 见下文 */
|
||
使用三路比较法比较两个值,并生成类型为
std::weak_ordering
的结果。
令
t
和
u
为表达式,且
T
和
U
分别表示
decltype
(
(
t
)
)
和
decltype
(
(
u
)
)
,则
std
::
weak_order
(
t, u
)
在
表达式等价性
上等同于:
-
如果
std::
is_same_v
<
std::
decay_t
<
T
>
,
std::
decay_t
<
U
>>
为
true
:
-
std::
weak_ordering
(
weak_order
(
t, u
)
)
,如果这是一个在未声明
std::weak_order的上下文中通过重载解析获得的合法表达式; -
否则,如果
T是浮点类型:-
若
std::
numeric_limits
<
T
>
::
is_iec559
为
true
,则执行浮点数值的弱序比较(详见下文)并返回类型为
std::weak_ordering的结果; -
否则,生成与
T的比较运算符所观察到的顺序一致的std::weak_ordering类型值;
-
若
std::
numeric_limits
<
T
>
::
is_iec559
为
true
,则执行浮点数值的弱序比较(详见下文)并返回类型为
- 否则, std:: weak_ordering ( std:: compare_three_way ( ) ( t, u ) ) ,如果该表达式合法;
- 否则, std:: weak_ordering ( std:: strong_order ( t, u ) ) ,如果该表达式合法。
-
std::
weak_ordering
(
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 均等价。
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
(C++20)
|
支持全部6种运算符但不可替换的三路比较结果类型
(类) |
|
(C++20)
|
执行三路比较并生成
std::strong_ordering
类型的结果
(定制点对象) |
|
(C++20)
|
执行三路比较并生成
std::partial_ordering
类型的结果
(定制点对象) |
|
(C++20)
|
执行三路比较并生成
std::weak_ordering
类型的结果,即使
operator
<=>
不可用
(定制点对象) |