“cpp/error/error code/operator cmp”的版本间的差异

来自cppreference.com
< cpp‎ | error‎ | error code
 
第2行: 第2行:
 
{{cpp/error/error_code/navbar}}
 
{{cpp/error/error_code/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl header | system_error}}
+
{{dcl header|system_error}}
{{dcl | num=1 | since=c++11 | 1=
+
{{dcl|num=1|since=c++11|1=
 
bool operator==( const std::error_code& lhs,
 
bool operator==( const std::error_code& lhs,
 
                 const std::error_code& rhs ) noexcept;
 
                 const std::error_code& rhs ) noexcept;
 
}}
 
}}
{{dcl | num=2 | since=c++11 | until=c++20 | 1=
+
{{dcl|num=2|since=c++11|until=c++20|1=
 
bool operator!=( const std::error_code& lhs,
 
bool operator!=( const std::error_code& lhs,
 
                 const std::error_code& rhs ) noexcept;
 
                 const std::error_code& rhs ) noexcept;
 
}}
 
}}
{{dcl | num=3 | since=c++11 | until=c++20 | 1=
+
{{dcl|num=3|since=c++11|until=c++20|1=
 
bool operator<( const std::error_code& lhs,
 
bool operator<( const std::error_code& lhs,
 
                 const std::error_code& rhs ) noexcept;
 
                 const std::error_code& rhs ) noexcept;
 
}}
 
}}
{{dcl | num=4 | since=c++20 | 1=
+
{{dcl|num=4|since=c++20|1=
 
std::strong_ordering operator<=>( const std::error_code& lhs,
 
std::strong_ordering operator<=>( const std::error_code& lhs,
 
                                   const std::error_code& rhs ) noexcept;
 
                                   const std::error_code& rhs ) noexcept;
第21行: 第21行:
 
{{dcl end}}
 
{{dcl end}}
  
 比较 error_code  对象。
+
 比较 个 对象。
  
@1@ 比较 {{tt|lhs}} 与 {{tt|rhs}} 的相等性。
+
@1@ 比较 {{|lhs}} 与 {{|rhs}} 的相等性。
@2@ 比较 {{tt|lhs}} 与 {{tt|rhs}} 的相等性。
+
@2@ 比较 {{|lhs}} 与 {{|rhs}} 的相等性。
@3@ 检查 {{tt|lhs}} 是否小于 {{tt|rhs}} 。  
+
@3@ 检查 {{|lhs}} 是否小于 {{|rhs}}。  
@4@ 获得 {{tt|lhs}} 与 {{tt|rhs}} 的三路比较结果。
+
@4@ 获得 {{|lhs}} 与 {{|rhs}} 的三路比较结果。
  
 
{{rrev | since=c++20 |
 
{{rrev | since=c++20 |
第34行: 第34行:
 
===参数===
 
===参数===
 
{{par begin}}
 
{{par begin}}
{{par | lhs, rhs | 要比较的 error_code }}
+
{{par | lhs, rhs | 要比较的 }}
 
{{par end}}
 
{{par end}}
  
 
===返回值===
 
===返回值===
@1@ 若错误类别和错误值比较相等则为 {{c|true}}
+
@1@ 若错误类别和错误值比较相等则为 {{c|true}}。
@2@ 若错误类别或错误值比较不相等则为 {{c|true}}
+
@2@ 若错误类别或错误值比较不相等则为 {{c|true}}。
@3@ 若 {{c|lhs.category() < rhs.category()}} 则为 {{c|true}} 。否则,若 {{c|1=lhs.category() == rhs.category() && lhs.value() < rhs.value()}} 则为 {{c|true}} 。否则为 {{c|false}}
+
@3@ 若 {{c|lhs.category() < rhs.category()}} 则为 {{c|true}}。否则,若 {{c|1=lhs.category() == rhs.category() && lhs.value() < rhs.value()}} 则为 {{c|true}}。否则为 {{c|false}}
@4@ 若 {{c|1=lhs.category() <=> rhs.category()}} 不为 {{c|std::strong_ordering::equal}} 则为该值。否则为 {{c|1=lhs.value() <=> rhs.value()}}
+
@4@ 若 {{c|1=lhs.category() <=> rhs.category()}} 不为 {{c|std::strong_ordering::equal}} 则为该值。否则为 {{c|1=lhs.value() <=> rhs.value()}}。
  
 
===参阅===
 
===参阅===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/error/error_code/dsc category}}
+
{{dsc inc|cpp/error/error_code/dsc category
 +
 +
}}
 
{{dsc end}}
 
{{dsc end}}
  
 
{{langlinks|de|en|es|fr|it|ja|pt|ru}}
 
{{langlinks|de|en|es|fr|it|ja|pt|ru}}

2023年12月1日 (五) 20:51的最后版本

 
 
 
 
 
在标头 <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 起)

比较两个错误码对象。

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

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

(C++20 起)

[编辑] 参数

lhs, rhs - 要比较的错误码

[编辑] 返回值

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()

[编辑] 参阅

获得此 error_code 的 error_category
(公开成员函数) [编辑]
获得 error_code 的值
(公开成员函数) [编辑]
(C++20 移除)(C++20 移除)(C++20)
比较 error_conditionerror_code
(函数) [编辑]