-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
error_code, error_condition, error_category : 三方比較演算子の追加と自動導出に対応 #900
- Loading branch information
1 parent
e06b66c
commit 26eca64
Showing
13 changed files
with
308 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <iostream> | ||
#include <system_error> | ||
|
||
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での三方比較演算子の追加と、関連する演算子の自動導出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <cassert> | ||
#include <system_error> | ||
|
||
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での三方比較演算子の追加と、関連する演算子の自動導出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <cassert> | ||
#include <system_error> | ||
|
||
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での三方比較演算子の追加と、関連する演算子の自動導出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.