Namespaces
Variants

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

来自 zh.cppreference.net
 
 
 
 
 
定义于头文件 <system_error>
bool operator==( const std::error_code& lhs,
                 const std::error_code& rhs ) noexcept;
(1) (自 C++11 起)
bool operator!=( const std::error_code& lhs,
                 const std::error_code& rhs ) noexcept;
(2) (自 C++11 起)
(直至 C++20)
bool operator<( const std::error_code& lhs,
                const std::error_code& rhs ) noexcept;
(3) (自 C++11 起)
(直至 C++20)
std::strong_ordering operator<=>( const std::error_code& lhs,
                                  const std::error_code& rhs ) noexcept;
(4) (自 C++20 起)

比较两个 error_code 对象。

1) 比较 lhs 与 rhs 是否相等。
2) 比较 lhs 与 rhs 是否相等。
3) 检查 lhs 是否小于 rhs。
4) 获取 lhs 与 rhs 的三路比较结果。

运算符 <、<=、>、>=、与 != 运算符是 合成自 operator<=> 与 operator== 分别。

(自 C++20 起)

参数

lhs, rhs - 待比较的错误码

返回值

1) true 当错误类别和错误值比较结果相等时。
2) true 当错误类别或错误值比较不相等时。
3) true 若 lhs. category ( ) < rhs. category ( ) 。否则, true 若 lhs. category ( ) == rhs. category ( ) && lhs. value ( ) < rhs. value ( ) 。否则, false 。
4) lhs. category ( ) <=> rhs. category ( ) 若其结果不是 std :: strong_ordering :: equal 。否则返回 lhs. value ( ) <=> rhs. value ( ) 。

参见

获取此 error_code 对应的错误类别
(公开成员函数)
获取 error_code 的值
(公开成员函数)
(C++20 中移除) (C++20 中移除) (C++20)
比较 error_condition 与 error_code
(函数)