operator==,!=,<,<=>(std::error_condition)

来自cppreference.com


 
 
 
 
 
在标头 <system_error> 定义
bool operator==( const std::error_condition& lhs,
                 const std::error_condition& rhs ) noexcept;
(1) (C++11 起)
bool operator!=( const std::error_condition& lhs,
                 const std::error_condition& rhs ) noexcept;
(2) (C++11 起)
(C++20 前)
bool operator<( const std::error_condition& lhs,
                const std::error_condition& rhs ) noexcept;
(3) (C++11 起)
(C++20 前)
std::strong_ordering operator<=>( const std::error_condition& lhs,
                                  const std::error_condition& rhs ) noexcept;
(4) (C++20 起)
bool operator==( const std::error_code& code,
                 const std::error_condition& cond ) noexcept;
(5) (C++11 起)
bool operator==( const std::error_condition& cond,
                 const std::error_code& code ) noexcept;
(5) (C++11 起)
(C++20 前)
bool operator!=( const std::error_code& code,
                 const std::error_condition& cond ) noexcept;
(6) (C++11 起)
(C++20 前)
bool operator!=( const std::error_condition& cond,
                 const std::error_code& code ) noexcept;
(6) (C++11 起)
(C++20 前)

比较两个错误条件。

1) 检查 lhsrhs 是否相等。
2) 检查 lhsrhs 是否不相等。
3) 检查 lhs 是否小于 rhs
4) 获得 lhsrhs 的三路比较结果。
5) 检查 code 是否为 cond 的语义匹配。
6) 检查 code 是否不是 cond 的语义匹配。

<<=>>=!= 运算符分别从 operator<=>operator== 合成

(C++20 起)

[编辑] 参数

lhs, rhs, cond - 要比较的错误条件
code - 要比较的错误码

[编辑] 返回值

1) 若错误类别与错误值比较相等则为 true
2) 若错误类别或错误值比较不相等则为 true
3)lhs.category() < rhs.category() 则为 true。否则若 lhs.category() == rhs.category() && lhs.value() < rhs.value() 则为 true。否则为 false
4)lhs.category() <=> rhs.category() 不为 std::strong_ordering::equal 则为该值。否则为 lhs.value() <=> rhs.value()
5)code.category().equivalent(code.value(), cond)cond.category().equivalent(code, cond.value()) 则为 true
6) 若既非 code.category().equivalent(code.value(), cond) 亦非 cond.category().equivalent(code, cond.value()) 则为 true

[编辑] 参阅

比较 error_codeerror_condition 的等价性
(std::error_category 的虚公开成员函数) [编辑]
(C++20 移除)(C++20 移除)(C++20)
比较两个 error_code
(函数) [编辑]