std::strong_ordering
在标头
<compare>
定义
|
||
class
strong_ordering;
|
(C++20 起) | |
类类型 std::strong_ordering
是这种三路比较的结果类型
- 接纳所有六个关系运算符( == 、 != 、 < 、 <= 、 > 、 >= )
- 隐含可替换性:若 a 等价于 b ,则 f(a) 亦等价于 f(b) 。这里 f 所指代的函数仅可经由参数的公开 const 成员读取显著的比较状态。换言之,等价的值不可区别。
- 不允许不可比较值: a < b 、 a == b 和 a > b 必须恰有一个为 true
常量
std::strong_ordering
类型拥有四个合法值,实现为其类型的 const 静态数据成员:
成员常量 | 定义 |
less(inline
constexpr)
[静态]
|
std::strong_ordering 类型合法值,指示小于(先序)关系 (公开静态成员常量) |
equivalent(inline
constexpr)
[静态]
|
std::strong_ordering 类型合法值,指示等价(既非先序亦非后序),等于
equal (公开静态成员常量) |
equal(inline
constexpr)
[静态]
|
std::strong_ordering 类型合法值,指示等价(既非先序亦非后序),等于
equivalent (公开静态成员常量) |
greater(inline
constexpr)
[静态]
|
std::strong_ordering 类型合法值,指示大于(后序)关系 (公开静态成员常量) |
转换
std::strong_ordering
是三个比较类别的最强者:它不能从任何其他类别隐式转换,而能隐式转换到其他二种类别。
operator
partial_ordering
|
到 std::partial_ordering 的隐式转换
(公开成员函数) |
std::strong_ordering::operator partial_ordering
constexpr
operator
partial_ordering()
const
noexcept;
|
||
返回值
若 v
为 less
则为 std::partial_ordering::less ,若
v
为 greater
则为 std::partial_ordering::greater ,若
v
为 equal
或 equivalent
则为
std::partial_ordering::equivalent 。
operator
weak_ordering
|
到 std::weak_ordering 的隐式转换 (公开成员函数) |
std::strong_ordering::operator weak_ordering
constexpr
operator
weak_ordering()
const
noexcept;
|
||
返回值
若 v
为 less
则为 std::weak_ordering::less ,若
v
为 greater
则为 std::weak_ordering::greater ,若
v
为 equal
或 equivalent
.
则为 std::weak_ordering::equivalent 。
比较
比较运算符在此类型值和字面量 0 间定义。这支持用表达式 a <=> b == 0 或 a <=> b < 0 转换三路比较的结果为布尔关系;见 std::is_eq 、 std::is_lt 等。
这些函数对通常无限定或有限定查找不可见,而只能在
std::strong_ordering
为参数的关联类时由实参依赖查找找到。
若程序试图将 strong_ordering
与任何异于整数字面量 0
的内容比较,则其行为未定义。
operator==operator<operator>operator<=operator>=operator<=>
|
与零或 strong_order 比较 (函数) |
operator==
friend
constexpr
bool
operator==(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
bool
operator==(strong_ordering
v, strong_ordering
w)
noexcept
=
default;
|
(2) | |
参数
v, w | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
equivalent
或 equal
则为 true ,若
v
为 less
或 greater
则为
false 。
equal
等于 equivalent
。
operator!=
friend
constexpr
bool
operator!=(strong_ordering
v, /*unspecified*/
u)
noexcept;
friend constexpr bool operator!=(/*unspecified*/ u, strong_ordering v) noexcept; |
||
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
若 v
为 less
或 greater
则为 true
,而若 v
为 equivalent
或
equal
则为 false 。
operator<
friend
constexpr
bool
operator<(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
bool
operator<(/*unspecified*/
u, strong_ordering
v)
noexcept;
|
(2) | |
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
less
则为 true
,而若 v
为 greater
、
equivalent
或 equal
则为 false 。
v
为
greater
则为 true
,而若 v
为 less
、 equivalent
或 equal
则为 false 。
operator<=
friend
constexpr
bool
operator<=(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
bool
operator<=(/*unspecified*/
u, strong_ordering
v)
noexcept;
|
(2) | |
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
less
、 equivalent
或 equal
则为 true
,而若 v
为 greater
则为 false 。
v
为
greater
、 equivalent
或
equal
则为 true
,而若 v
为 less
则为 false 。
operator>
friend
constexpr
bool
operator>(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
bool
operator>(/*unspecified*/
u, strong_ordering
v)
noexcept;
|
(2) | |
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
greater
则为 true
,而若 v
为 less
、 equivalent
或 equal
则为 false 。
v
为
less
则为 true
,而若 v
为 greater
、
equivalent
或 equal
则为 false 。
operator>=
friend
constexpr
bool
operator>=(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
bool
operator>=(/*unspecified*/
u, strong_ordering
v)
noexcept;
|
(2) | |
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
greater
、 equivalent
或
equal
则为 true
,而若 v
为 less
则为 false 。
v
为
less
、 equivalent
或 equal
则为 true
,而若 v
为 greater
则为 false 。
operator<=>
friend
constexpr
strong_ordering
operator<=>(strong_ordering
v, /*unspecified*/
u)
noexcept;
|
(1) | |
friend
constexpr
strong_ordering
operator<=>(/*unspecified*/
u, strong_ordering
v)
noexcept;
|
(2) | |
参数
v | - | 要检查的 std::strong_ordering 值
|
u | - | 任何接受字面零实参的类型的不使用形参 |
返回值
v
为
less
则为 greater
,若 v
为
greater
则为 less
,否则为 v
。
示例
本节未完成 原因:暂无示例 |
参阅
(C++20)
|
三路比较的结果类型,支持所有 6 种运算符且不可替换 (类) |
(C++20)
|
三路比较的结果类型,支持所有 6 种运算符,不可替换,并允许不可比较的值 (类) |