std:: weak_ordering
|
定义于头文件
<compare>
|
||
|
class
weak_ordering
;
|
(C++20 起) | |
类类型
std::weak_ordering
是
三路比较
的结果类型,其特性为:
-
支持全部六种关系运算符(
==,!=,<,<=,>,>=)。
- 不意味着可替换性:若 a 等价于 b ,则 f ( a ) 可能不等价于 f ( b ) ,其中 f 表示仅读取通过实参的公开常量成员可访问的、与比较相关的状态的函数。换言之,等价的值可能是可区分的。
- 不允许不可比较的值 : a < b 、 a == b 或 a > b 中必须有且仅有一个为 true 。
目录 |
常量
类型
std::weak_ordering
具有三个有效值,通过其类型的常量静态数据成员实现:
| 名称 | 定义 |
|
inline
constexpr
std
::
weak_ordering
less
[static]
|
表示小于(排序在前)关系的有效值
(公开静态成员常量) |
|
inline
constexpr
std
::
weak_ordering
equivalent
[static]
|
表示等价(既不排序在前也不排序在后)的有效值
(公开静态成员常量) |
|
inline
constexpr
std
::
weak_ordering
greater
[static]
|
表示大于(排序在后)关系的有效值
(公开静态成员常量) |
转换
std::weak_ordering
可隐式转换为
std::partial_ordering
,而
std::strong_ordering
可隐式转换为
weak_ordering
。
|
operator partial_ordering
|
隐式转换为
std::partial_ordering
(公开成员函数) |
std::weak_ordering:: operator partial_ordering
|
constexpr
operator partial_ordering
(
)
const
noexcept
;
|
||
返回值
若
v
为
less
则返回
std::partial_ordering::less
,若
v
为
greater
则返回
std::partial_ordering::greater
,
若
v
为
equivalent
则返回
std::partial_ordering::equivalent
。
比较操作
此类型的值与字面量 0 之间定义了比较运算符。这支持表达式 a <=> b == 0 或 a <=> b < 0 ,可用于将三路比较运算符的结果转换为布尔关系;参见 std::is_eq 、 std::is_lt 等。
这些函数对普通的
非限定查找
或
限定查找
不可见,仅当
std::weak_ordering
作为参数的关联类时,通过
实参依赖查找
才能找到它们。
试图将
weak_ordering
与除整数字面量
0
之外的任何值进行比较的程序行为是未定义的。
|
operator==
operator<
operator>
operator<=
operator>=
operator<=>
|
与零或
weak_ordering
进行比较
(函数) |
operator==
|
friend
constexpr
bool
operator
==
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
bool
operator
==
(
weak_ordering v, weak_ordering w
)
noexcept
=
default
;
|
(2) | |
参数
| v, w | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面量零参数的任何类型的未使用参数 |
返回值
v
为
equivalent
,
false
如果
v
为
less
或
greater
operator<
|
friend
constexpr
bool
operator
<
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
bool
operator
<
(
/*unspecified*/
u, weak_ordering v
)
noexcept
;
|
(2) | |
参数
| v | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面零参数的任何类型的未使用参数 |
返回值
v
为
less
,
false
如果
v
为
greater
或
equivalent
v
为
greater
,
false
如果
v
为
less
或
equivalent
operator<=
|
friend
constexpr
bool
operator
<=
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
bool
operator
<=
(
/*unspecified*/
u, weak_ordering v
)
noexcept
;
|
(2) | |
参数
| v | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面零参数的任何类型的未使用参数 |
返回值
v
为
less
或
equivalent
,
false
如果
v
为
greater
v
为
greater
或
equivalent
,
false
如果
v
为
less
operator>
|
friend
constexpr
bool
operator
>
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
bool
operator
>
(
/*unspecified*/
u, weak_ordering v
)
noexcept
;
|
(2) | |
参数
| v | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面零参数的任何类型的未使用参数 |
返回值
v
为
greater
,
false
如果
v
为
less
或
equivalent
v
为
less
,
false
如果
v
为
greater
或
equivalent
operator>=
|
friend
constexpr
bool
operator
>=
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
bool
operator
>=
(
/*unspecified*/
u, weak_ordering v
)
noexcept
;
|
(2) | |
参数
| v | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面零参数的任何类型的未使用参数 |
返回值
v
为
greater
或
equivalent
,
false
如果
v
为
less
v
为
less
或
equivalent
,
false
如果
v
为
greater
operator<=>
|
friend
constexpr
weak_ordering operator
<=>
(
weak_ordering v,
/*unspecified*/
u
)
noexcept
;
|
(1) | |
|
friend
constexpr
weak_ordering operator
<=>
(
/*unspecified*/
u, weak_ordering v
)
noexcept
;
|
(2) | |
参数
| v | - |
要检查的
std::weak_ordering
值
|
| u | - | 接受字面量零参数的任何类型的未使用参数 |
返回值
v
为
less
则返回
greater
,若
v
为
greater
则返回
less
,否则返回
v
。
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
(C++20)
|
支持全部6种运算符且可替换的三路比较结果类型
(类) |
|
(C++20)
|
支持全部6种运算符、不可替换且允许不可比较值的三路比较结果类型
(类) |