std::strong_equality
来自cppreference.com
| 定义于头文件 <compare>
|
||
| class strong_equality; |
(C++20 起) | |
类类型 std::strong_equality 是这种三路比较的结果类型:
- 仅接纳相等和不等比较(非小于/大于)
- 隐含可替换性:若 a 等价于 b ,则 f(a) 亦等价于 f(b) 。这里 f 所指代的函数仅可经由参数的公开 const 成员读取显著的比较状态。换言之,等价的值不可区别。
目录 |
[编辑] 常量
类型 std::strong_equality 拥有四个合法值,作为其类型的 const 静态数据成员实现:
| 成员常量 | 定义 |
| equivalent(inline constexpr) [静态] |
std::strong_equality 类型的合法值,指示相等 (公开静态成员常量) |
| equal(inline constexpr) [静态] |
std::strong_equality 类型的合法值,指示相等 (公开静态成员常量) |
| nonequivalent(inline constexpr) [静态] |
std::strong_equality 类型的合法值,指示不相等 (公开静态成员常量) |
| nonequal(inline constexpr) [静态] |
std::strong_equality 类型的合法值,指示不相等 (公开静态成员常量) |
[编辑] 转换
std::strong_equality 可隐式转换为 std::weak_equality ,而 std::strong_ordering 可隐式转换为 strong_equality 。
| operator weak_equality |
到 std::weak_equality 的隐式转换 (公开成员函数) |
std::strong_equality::operator weak_equality
| constexpr operator weak_equality() const noexcept; |
||
返回值
若 v 为 equivalent 或 equal 则为 std::weak_equality::equivalent ,若 v 为 nonequivalent 或 nonequal 则为 std::weak_equality::nonequivalent 。
[编辑] 比较
比较运算符在此类型和字面量 0 间定义。这支持用表达式 a <=> b == 0 和 a <=> b != 0 转换三路比较运算符的结果为布尔关系;见 std::is_eq 与 std::is_neq 。
若程序试图将 strong_equality 与任何异于整数字面量 0 的内容比较,则其行为未定义。
| operator==operator!=operator<=> |
与零比较 (函数) |
operator==
| friend constexpr bool operator==(strong_equality v, /*unspecified*/ u) noexcept; friend constexpr bool operator==(/*unspecified*/ u, strong_equality v) noexcept; |
||
参数
| v | - | 要检查的 std::strong_equality 值
|
| u | - | 接受字面零实参的任何类型不使用形参 |
返回值
若 v 为 equivalent 或 equal 则为 true ,而若 v 为 nonequivalent 或 nonequal 则为 false 。
operator!=
| friend constexpr bool operator!=(strong_equality v, /*unspecified*/ u) noexcept; friend constexpr bool operator!=(/*unspecified*/ u, strong_equality v) noexcept; |
||
参数
| v | - | 要检查的 std::strong_equality 值
|
| u | - | 接受字面零实参的任何类型不使用形参 |
返回值
若 v 为 equivalent 或 equal 则为 false ,而若 v 为 nonequivalent 或 nonequal 则为 true 。
operator<=>
| friend constexpr strong_equality operator<=>(strong_equality v, /*unspecified*/ u) noexcept; friend constexpr strong_equality operator<=>(/*unspecified*/ u, strong_equality v) noexcept; |
||
参数
| v | - | 要检查的 std::strong_equality 值
|
| u | - | 接受字面零实参的任何类型不使用形参 |
返回值
v
[编辑] 示例
| 本节未完成 原因:暂无示例 |
[编辑] 参阅
| (C++20) |
三路比较的结果类型,支持所有 6 种运算符且可替换 (类) |
| (C++20) |
三路比较的结果类型,支持所有 6 种运算符且不可替换 (类) |
| (C++20) |
三路比较的结果类型,支持所有 6 种运算符,不可替换,并允许不可比较的值 (类) |
| (C++20) |
三路比较的结果类型,仅支持相等/不相等,且不可替换 (类) |

