Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expected: bad_expected_access<E>(#1066)
- Loading branch information
Showing
10 changed files
with
202 additions
and
15 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,71 @@ | ||
# error | ||
* expected[meta header] | ||
* function[meta id-type] | ||
* std[meta namespace] | ||
* bad_expected_access[meta class] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr const E& error() const & noexcept; // (1) | ||
constexpr E& error() & noexcept; // (2) | ||
constexpr const E&& error() const && noexcept; // (3) | ||
constexpr E&& error() && noexcept; // (4) | ||
``` | ||
|
||
## 概要 | ||
エラー値を取得する。 | ||
|
||
|
||
## 戻り値 | ||
動作説明用のメンバ変数として、エラー値を保持する`unex`を導入する。 | ||
|
||
- (1), (2) : `unex` | ||
- (3), (4) : [`std::move`](/reference/utility/move.md)`(unex)` | ||
|
||
|
||
## 例外 | ||
投げない | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <cassert> | ||
#include <expected> | ||
#include <iostream> | ||
#include <string> | ||
|
||
int main() | ||
{ | ||
std::expected<int, std::string> v = std::unexpected{"ERR"}; | ||
try { | ||
std::cout << v.value() << std::endl; | ||
} catch (const std::bad_expected_access<std::string>& ex) { | ||
std::cout << "throw:" << ex.error() << std::endl; | ||
} | ||
} | ||
``` | ||
* error()[color ff0000] | ||
* value()[link ../expected/value.md] | ||
* std::unexpected[link ../unexpected.md] | ||
* std::bad_expected_access[link ../bad_expected_access.md] | ||
|
||
### 出力 | ||
``` | ||
throw:ERR | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): 16.0 | ||
- [GCC](/implementation.md#gcc): 12.1 | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 参照 | ||
- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html) | ||
- [P2549R1 `std::unexpected<E>` should have `error()` as member accessor](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2549r1.html) |
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,52 @@ | ||
# コンストラクタ | ||
* expected[meta header] | ||
* function[meta id-type] | ||
* std[meta namespace] | ||
* bad_expected_access[meta class] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
explicit bad_expected_access(E e); // (1) | ||
bad_expected_access(const bad_expected_access&); // (2) | ||
bad_expected_access(bad_expected_access&&); // (3) | ||
``` | ||
* bad_expected_access[link ../bad_expected_access.md] | ||
## 概要 | ||
- (1) : エラー値を[`std::move`](/reference/utility/move.md)`(e)`で初期化する。 | ||
- (2) : コピーコンストラクタ。 | ||
- (3) : ムーブコンストラクタ。 | ||
## 例 | ||
```cpp example | ||
#include <cassert> | ||
#include <expected> | ||
int main() | ||
{ | ||
std::bad_expected_access<int> ex{42}; | ||
assert(ex.error() == 42); | ||
} | ||
``` | ||
* std::bad_expected_access[color ff0000] | ||
* error()[link error.md] | ||
|
||
### 出力 | ||
``` | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): 16.0 | ||
- [GCC](/implementation.md#gcc): 12.1 | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 参照 | ||
- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html) |
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,64 @@ | ||
# what | ||
* expected[meta header] | ||
* function[meta id-type] | ||
* std[meta namespace] | ||
* bad_expected_access[meta class] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
const char* what() const noexcept override; | ||
``` | ||
|
||
## 概要 | ||
エラー理由の文字列を取得する。 | ||
|
||
|
||
## 戻り値 | ||
エラー理由となる実装定義の文字列 | ||
|
||
|
||
## 例外 | ||
投げない | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <cassert> | ||
#include <expected> | ||
#include <iostream> | ||
#include <string> | ||
|
||
int main() | ||
{ | ||
std::expected<int, std::string> v = std::unexpected{"ERR"}; | ||
try { | ||
std::cout << v.value() << std::endl; | ||
} catch (const std::bad_expected_access<std::string>& ex) { | ||
std::cout << ex.what() << std::endl; | ||
} | ||
} | ||
``` | ||
* what()[color ff0000] | ||
* value()[link ../expected/value.md] | ||
* std::unexpected[link ../unexpected.md] | ||
* std::bad_expected_access[link ../bad_expected_access.md] | ||
|
||
### 出力例 | ||
``` | ||
bad access to std::expected without expected value | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): 16.0 | ||
- [GCC](/implementation.md#gcc): 12.1 | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 参照 | ||
- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html) |
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
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 |
---|---|---|
|
@@ -12,7 +12,7 @@ namespace std { | |
``` | ||
## 概要 | ||
`std::expected`クラステンプレートの型推論補助。 | ||
`std::unexpected`クラステンプレートの型推論補助。 | ||
## 例 | ||
|