From 26eca643fa3060f50feedb62a0bb4596382ccbb0 Mon Sep 17 00:00:00 2001 From: Akira Takahashi Date: Wed, 14 Dec 2022 02:59:40 +0900 Subject: [PATCH] =?UTF-8?q?error=5Fcode,=20error=5Fcondition,=20error=5Fca?= =?UTF-8?q?tegory=20:=20=E4=B8=89=E6=96=B9=E6=AF=94=E8=BC=83=E6=BC=94?= =?UTF-8?q?=E7=AE=97=E5=AD=90=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=81=A8=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E5=B0=8E=E5=87=BA=E3=81=AB=E5=AF=BE=E5=BF=9C=20#900?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/system_error/error_category.md | 14 +++- .../error_category/op_compare_3way.md | 79 +++++++++++++++++++ .../system_error/error_category/op_equal.md | 7 +- .../system_error/error_category/op_less.md | 5 +- .../error_category/op_not_equal.md | 5 +- reference/system_error/error_code.md | 8 +- .../error_code/op_compare_3way.md | 78 ++++++++++++++++++ reference/system_error/error_code/op_less.md | 5 +- reference/system_error/error_condition.md | 9 ++- .../error_condition/op_compare_3way.md | 78 ++++++++++++++++++ .../system_error/error_condition/op_less.md | 5 +- reference/system_error/op_equal.md | 33 ++++---- reference/system_error/op_not_equal.md | 16 ++-- 13 files changed, 308 insertions(+), 34 deletions(-) create mode 100644 reference/system_error/error_category/op_compare_3way.md create mode 100644 reference/system_error/error_code/op_compare_3way.md create mode 100644 reference/system_error/error_condition/op_compare_3way.md diff --git a/reference/system_error/error_category.md b/reference/system_error/error_category.md index 887f2efbf3..26ee36c2dd 100644 --- a/reference/system_error/error_category.md +++ b/reference/system_error/error_category.md @@ -17,6 +17,7 @@ namespace std { ## メンバ関数 +### 構築・破棄 | 名前 | 説明 | 対応バージョン | |------|------|----------------| @@ -24,10 +25,19 @@ namespace std { | [`(destructor)`](error_category/op_destructor.md) | デストラクタ | C++11 | | `operator=(const error_category&) = delete` | 代入演算子(使用不可) | C++11 | | [`default_error_condition`](error_category/default_error_condition.md) | エラー値と自身のカテゴリから`error_condition`を生成 | C++11 | + +### 比較 + +| 名前 | 説明 | 対応バージョン | +|------|------|----------------| | [`equivalent`](error_category/equivalent.md) | エラーコードとエラー状態の等値比較 | C++11 | -| [`operator==`](error_category/op_equal.md) | 等値比較 | C++11 | +| [`operator==`](error_category/op_equal.md) | 等値比較 (C++20から`operator<=>`により使用可能) | C++11 | | [`operator!=`](error_category/op_not_equal.md) | 非等値比較 | C++11 | -| [`operator<`](error_category/op_less.md) | 小なり比較 | C++11 | +| [`operator<=>`](error_category/op_compare_3way.md) | 三方比較 | C++20 | +| [`operator<`](error_category/op_less.md) | 左辺が右辺より小さいか比較 (C++20から`operator<=>`により使用可能) | C++11 | +| `bool operator<=(const error_category&) const noexcept;` | 左辺が右辺以下か比較 (`operator<=>`により使用可能) | C++20 | +| `bool operator>(const error_category&) const noexcept;` | 左辺が右辺より大きいか比較 (`operator<=>`により使用可能) | C++20 | +| `bool operator>=(const error_category&) const noexcept;` | 左辺が右辺以上か比較 (`operator<=>`により使用可能) | C++20 | ### 純粋仮想関数 diff --git a/reference/system_error/error_category/op_compare_3way.md b/reference/system_error/error_category/op_compare_3way.md new file mode 100644 index 0000000000..ca3e16c59e --- /dev/null +++ b/reference/system_error/error_category/op_compare_3way.md @@ -0,0 +1,79 @@ +# operator<=> +* system_error[meta header] +* std[meta namespace] +* error_category[meta class] +* function[meta id-type] +* cpp20[meta cpp] + +```cpp +strong_ordering operator<=>(const error_category& rhs) const noexcept; // (1) C++11 +``` + +## 概要 +`error_category`オブジェクトの三方比較を行う。 + + +## 戻り値 +```cpp +return compare_three_way()(this, &rhs); +``` +* compare_three_way[link /reference/compare/compare_three_way.md] + + +## 例外 +投げない + + +## 備考 +- この演算子により、以下の演算子が使用可能になる (C++20): + - `operator<` + - `operator<=` + - `operator>` + - `operator>=` + + +## 例 +```cpp example +#include +#include + +int main() +{ + const std::error_category& a = std::generic_category(); + const std::error_category& b = std::generic_category(); + const std::error_category& c = std::system_category(); + + std::cout << std::boolalpha; + + std::cout << ((a <=> b) == 0) << std::endl; + std::cout << (a < c) << std::endl; + std::cout << (a <= c) << std::endl; + std::cout << (a > c) << std::endl; + std::cout << (a >= c) << std::endl; +} +``` +* std::generic_category()[link /reference/system_error/generic_category.md] +* std::system_category()[link /reference/system_error/system_category.md] + +### 出力例 +``` +true +false +false +true +true +``` + +## バージョン +### 言語 +- C++20 + +### 処理系 +- [Clang](/implementation.md#clang): +- [GCC](/implementation.md#gcc): 10 +- [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/error_category/op_equal.md b/reference/system_error/error_category/op_equal.md index c1717b523d..b1f26b0c3a 100644 --- a/reference/system_error/error_category/op_equal.md +++ b/reference/system_error/error_category/op_equal.md @@ -6,7 +6,7 @@ * cpp11[meta cpp] ```cpp -bool operator==(const error_category& rhs) const noexcept; +bool operator==(const error_category& rhs) const noexcept; // (1) C++11 ``` ## 概要 @@ -23,6 +23,11 @@ bool operator==(const error_category& rhs) const noexcept; 投げない +## 備考 +- この演算子により、以下の演算子が使用可能になる (C++20): + - `operator!=` + + ## 例 ```cpp example #include diff --git a/reference/system_error/error_category/op_less.md b/reference/system_error/error_category/op_less.md index 873dfaeeed..6274b03736 100644 --- a/reference/system_error/error_category/op_less.md +++ b/reference/system_error/error_category/op_less.md @@ -6,7 +6,8 @@ * cpp11[meta cpp] ```cpp -bool operator<(const error_category& rhs) const noexcept; +// operator<=>により、以下の演算子が使用可能になる (C++20) +bool operator<(const error_category& rhs) const noexcept; // (1) C++11 ``` ## 概要 @@ -61,3 +62,5 @@ false ## 参照 +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/error_category/op_not_equal.md b/reference/system_error/error_category/op_not_equal.md index eedbc9a9d0..aebcc0c341 100644 --- a/reference/system_error/error_category/op_not_equal.md +++ b/reference/system_error/error_category/op_not_equal.md @@ -6,7 +6,8 @@ * cpp11[meta cpp] ```cpp -bool operator!=(const error_category& rhs) const noexcept; +// operator==により、以下の演算子が使用可能になる (C++20) +bool operator!=(const error_category& rhs) const noexcept; // (1) C++11 ``` ## 概要 @@ -61,3 +62,5 @@ true ## 参照 +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/error_code.md b/reference/system_error/error_code.md index e7528921a3..d2b1e46f3a 100644 --- a/reference/system_error/error_code.md +++ b/reference/system_error/error_code.md @@ -37,8 +37,12 @@ namespace std { | 名前 | 説明 | 対応バージョン | |------|------|----------------| | [`operator==`](op_equal.md) | 等値比較 | C++11 | -| [`operator!=`](op_not_equal.md) | 非等値比較 | C++11 | -| [`operator<`](error_code/op_less.md) | 左辺が右辺より小さいか判定する | C++11 | +| [`operator!=`](op_not_equal.md) | 非等値比較 (C++20から`operator<=>`により使用可能) | C++11 | +| [`operator<=>`](error_code/op_compare_3way.md) | 三方比較 | C++20 | +| [`operator<`](error_code/op_less.md) | 左辺が右辺より小さいか判定する (C++20から`operator<=>`により使用可能) | C++11 | +| `bool operator<=(const error_code&, const error_code&) noexcept;` | 左辺が右辺以下か判定する (`operator<=>`により使用可能) | C++20 | +| `bool operator>(const error_code&, const error_code&) noexcept;` | 左辺が右辺より大きいか判定する (`operator<=>`により使用可能) | C++20 | +| `bool operator>=(const error_code&, const error_code&) noexcept;` | 左辺が右辺以上か判定する (`operator<=>`により使用可能) | C++20 | | [`operator<<`](error_code/op_ostream.md) | ストリームへ出力 | C++11 | | [`make_error_code`](make_error_code.md) | `errc`から`error_code`オブジェクトを生成する | C++11 | diff --git a/reference/system_error/error_code/op_compare_3way.md b/reference/system_error/error_code/op_compare_3way.md new file mode 100644 index 0000000000..e69eca5317 --- /dev/null +++ b/reference/system_error/error_code/op_compare_3way.md @@ -0,0 +1,78 @@ +# operator<=> +* system_error[meta header] +* std[meta namespace] +* function[meta id-type] +* cpp20[meta cpp] + +```cpp +namespace std { + strong_ordering + operator<=>(const error_code& lhs, + const error_code& rhs) noexcept; // (1) C++20 +} +``` + +## 概要 +`error_code`オブジェクトの三方比較を行う。 + + +## 効果 +以下と等価: + +```cpp +if (auto c = lhs.category() <=> rhs.category(); c != 0) + return c; +return lhs.value() <=> rhs.value(); +``` +* category()[link category.md] +* value()[link value.md] + + +## 例外 +投げない + + +## 備考 +- この演算子により、以下の演算子が使用可能になる (C++20): + - `operator<` + - `operator<=` + - `operator>` + - `operator>=` + + +## 例 +```cpp example +#include +#include + +int main() +{ + std::error_code ec1 = std::make_error_code(std::errc::invalid_argument); + std::error_code ec2 = std::make_error_code(std::errc::invalid_argument); + std::error_code ec3 = std::make_error_code(std::errc::permission_denied); + + assert((ec1 <=> ec2) == 0); + assert((ec1 <=> ec3) != 0); +} +``` +* std::make_error_code[link /reference/system_error/make_error_code.md] +* std::errc::invalid_argument[link /reference/system_error/errc.md] +* std::errc::permission_denied[link /reference/system_error/errc.md] + +### 出力 +``` +``` + +## バージョン +### 言語 +- C++20 + +### 処理系 +- [Clang](/implementation.md#clang): +- [GCC](/implementation.md#gcc): 10 +- [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/error_code/op_less.md b/reference/system_error/error_code/op_less.md index 4a547de6cf..ff4d23a499 100644 --- a/reference/system_error/error_code/op_less.md +++ b/reference/system_error/error_code/op_less.md @@ -6,7 +6,10 @@ ```cpp namespace std { - bool operator<(const error_code& lhs, const error_code& rhs) noexcept; + // operator<=>により、以下の演算子が使用可能になる (C++20) + bool + operator<(const error_code& lhs, + const error_code& rhs) noexcept; // (1) C++11 } ``` diff --git a/reference/system_error/error_condition.md b/reference/system_error/error_condition.md index ffa845b96e..5f6a2ef798 100644 --- a/reference/system_error/error_condition.md +++ b/reference/system_error/error_condition.md @@ -40,8 +40,13 @@ Visual C++ 2010、GCC 4.6.1では[`generic_category()`](generic_category.md)と[ | 名前 | 説明 | 対応バージョン | |------|------|----------------| | [`operator==`](op_equal.md) | 等値比較 | C++11 | -| [`operator!=`](op_not_equal.md) | 非等値比較 | C++11 | -| [`operator<`](error_condition/op_less.md) | 左辺が右辺より小さいか判定する | C++11 | +| [`operator!=`](op_not_equal.md) | 非等値比較 (C++20から`operator<=>`により使用可能) | C++11 | +| [`operator<=>`](error_condition/op_compare_3way.md) | 三方比較 | C++20 | +| [`operator<`](error_condition/op_less.md) | 左辺が右辺より小さいか判定する (C++20から`operator<=>`により使用可能) | C++11 | +| `bool operator<=(const error_condition&, const error_condition&) noexcept;` | 左辺が右辺以下か判定する (`operator<=>`により使用可能) | C++20 | +| `bool operator>(const error_condition&, const error_condition&) noexcept;` | 左辺が右辺より大きいか判定する (`operator<=>`により使用可能) | C++20 | +| `bool operator>=(const error_condition&, const error_condition&) noexcept;` | 左辺が右辺以上か判定する (`operator<=>`により使用可能) | C++20 | + | [`make_error_condition`](make_error_condition.md) | `errc`から`error_condition`オブジェクトを生成する | C++11 | diff --git a/reference/system_error/error_condition/op_compare_3way.md b/reference/system_error/error_condition/op_compare_3way.md new file mode 100644 index 0000000000..0e7991235f --- /dev/null +++ b/reference/system_error/error_condition/op_compare_3way.md @@ -0,0 +1,78 @@ +# operator<=> +* system_error[meta header] +* std[meta namespace] +* function[meta id-type] +* cpp20[meta cpp] + +```cpp +namespace std { + strong_ordering + operator<=>(const error_condition& lhs, + const error_condition& rhs) noexcept; // (1) C++20 +} +``` + +## 概要 +`error_condition`オブジェクトの三方比較を行う。 + + +## 効果 +以下と等価: + +```cpp +if (auto c = lhs.category() <=> rhs.category(); c != 0) + return c; +return lhs.value() <=> rhs.value(); +``` +* category()[link category.md] +* value()[link value.md] + + +## 例外 +投げない + + +## 備考 +- この演算子により、以下の演算子が使用可能になる (C++20): + - `operator<` + - `operator<=` + - `operator>` + - `operator>=` + + +## 例 +```cpp example +#include +#include + +int main() +{ + std::error_condition ec1 = std::make_error_condition(std::errc::invalid_argument); + std::error_condition ec2 = std::make_error_condition(std::errc::invalid_argument); + std::error_condition ec3 = std::make_error_condition(std::errc::permission_denied); + + assert((ec1 <=> ec2) == 0); + assert((ec1 <=> ec3) != 0); +} +``` +* std::make_error_condition[link /reference/system_error/make_error_condition.md] +* std::errc::invalid_argument[link /reference/system_error/errc.md] +* std::errc::permission_denied[link /reference/system_error/errc.md] + +### 出力 +``` +``` + +## バージョン +### 言語 +- C++20 + +### 処理系 +- [Clang](/implementation.md#clang): +- [GCC](/implementation.md#gcc): 10 +- [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/error_condition/op_less.md b/reference/system_error/error_condition/op_less.md index 033d18ff0e..9ab45fb4ca 100644 --- a/reference/system_error/error_condition/op_less.md +++ b/reference/system_error/error_condition/op_less.md @@ -6,7 +6,10 @@ ```cpp namespace std { - bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; + // operator<=>により、以下の演算子が使用可能になる (C++20) + bool + operator<(const error_condition& lhs, + const error_condition& rhs) noexcept; // (1) C++11 } ``` diff --git a/reference/system_error/op_equal.md b/reference/system_error/op_equal.md index 87ac1967ab..b6221a0e7b 100644 --- a/reference/system_error/op_equal.md +++ b/reference/system_error/op_equal.md @@ -6,10 +6,12 @@ ```cpp namespace std { - bool operator==(const error_code& lhs, const error_code& rhs) noexcept; // (1) - bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; // (2) - bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; // (3) - bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; // (4) + bool operator==(const error_code& lhs, const error_code& rhs) noexcept; // (1) C++11 + bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; // (2) C++11 + bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; // (3) C++11 + + // (2)により以下のオーバーロードが使用可能になる (C++20) + bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; // (4) C++11 } ``` * error_code[link /reference/system_error/error_code.md] @@ -21,7 +23,6 @@ namespace std { ## 戻り値 - (1) : - ```cpp lhs.category() == rhs.category() && lhs.value() == rhs.value() ``` @@ -30,7 +31,6 @@ namespace std { - (2) : - ```cpp lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value()) ``` @@ -40,9 +40,15 @@ namespace std { * lhs.value()[link error_code/value.md] * rhs.value()[link error_condition/value.md] - - (3) : + ```cpp + lhs.category() == rhs.category() && lhs.value() == rhs.value() + ``` + * category()[link error_condition/category.md] + * value()[link error_condition/value.md] + +- (4) : ```cpp rhs.category().equivalent(rhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value()) ``` @@ -53,15 +59,6 @@ namespace std { * rhs.value()[link error_code/value.md] -- (4) : - - ```cpp - lhs.category() == rhs.category() && lhs.value() == rhs.value() - ``` - * category()[link error_condition/category.md] - * value()[link error_condition/value.md] - - ## 例外 投げない @@ -120,5 +117,5 @@ error_condition == error_condition : false ## 参照 - - +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出 diff --git a/reference/system_error/op_not_equal.md b/reference/system_error/op_not_equal.md index 9c6d48b217..0e061e8b6c 100644 --- a/reference/system_error/op_not_equal.md +++ b/reference/system_error/op_not_equal.md @@ -6,10 +6,11 @@ ```cpp namespace std { - bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; - bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; - bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; - bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; + // operator==により、以下の演算子が使用可能になる (C++20) + bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; // (1) C++11 + bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; // (2) C++11 + bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; // (3) C++11 + bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; // (4) C++11 } ``` * error_code[link error_code.md] @@ -80,5 +81,10 @@ error_condition != error_condition : true - [Visual C++](/implementation.md#visual_cpp): 2010 +## 関連項目 +- [`operator==()`](op_equal.md) + + ## 参照 -[`operator==()`](op_equal.md) +- [P1614R2 The Mothership has Landed](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html) + - C++20での三方比較演算子の追加と、関連する演算子の自動導出