std::weak_ordering
来自 cppreference.cn
                    
                                        
                    
                    
                                                            
                    | 定义于头文件  <compare> | ||
| class weak_ordering; | (C++20 起) | |
类类型 std::weak_ordering 是 三路比较 的结果类型,它
- 允许所有六种关系运算符(==、!=、<、<=、>、>=)。
- 不暗示可替代性:如果 a 等价于 b,则 f(a) 可能不等价于 f(b),其中 f 表示一个函数,它只读取可通过参数的 public const 成员访问的比较显著状态。换句话说,等价的值可能可区分。
- 不允许不可比较的值:a < b、a == b 或 a > b 中恰好有一个必须为 true。
| 目录 | 
[编辑] 常量
类型 std::weak_ordering 有三个有效值,以其类型的 const static 数据成员实现
| 名称 | 定义 | 
| inline constexpr std::weak_ordering less [静态] | 一个有效值,表示小于(排在前面)关系 (public static 成员常量) | 
| inline constexpr std::weak_ordering equivalent [静态] | 一个表示等价的有效值(既不排在前面也不排在后面) (public static 成员常量) | 
| inline constexpr std::weak_ordering greater [静态] | 一个有效值,表示大于(排在后面)关系 (public 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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) 如果 
v 是 equivalent,则为 true;如果 v 是 less 或 greater,则为 false2) 如果两个参数持有相同的值,则为 true;否则为 false
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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) 如果 
v 是 less,则为 true;如果 v 是 greater 或 equivalent,则为 false2) 如果 
v 是 greater,则为 true;如果 v 是 less 或 equivalent,则为 falseoperator<=
| 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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) 如果 
v 是 less 或 equivalent,则为 true;如果 v 是 greater,则为 false2) 如果 
v 是 greater 或 equivalent,则为 true;如果 v 是 less,则为 falseoperator>
| 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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) 如果 
v 是 greater,则为 true;如果 v 是 less 或 equivalent,则为 false2) 如果 
v 是 less,则为 true;如果 v 是 greater 或 equivalent,则为 falseoperator>=
| 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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) 如果 
v 是 greater 或 equivalent,则为 true;如果 v 是 less,则为 false2) 如果 
v 是 less 或 equivalent,则为 true;如果 v 是 greater,则为 falseoperator<=>
| 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 | - | 接受字面量零参数的任何类型的未使用参数 | 
返回值
1) v。
2) 如果 
v 是 less,则为 greater;如果 v 是 greater,则为 less;否则为 v。[编辑] 示例
| 本节不完整 原因:无示例 | 
[编辑] 参见
| (C++20) | 支持所有6个操作符并且可替换的三路比较的结果类型 (类) | 
| (C++20) | 支持所有6个操作符,不可替换,并允许不可比较值的三路比较的结果类型 (类) | 


