Skip to content

Commit

Permalink
expected: expectedクラス概要のみ(#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Jan 25, 2023
1 parent 74662b4 commit e400d17
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 2 deletions.
2 changes: 2 additions & 0 deletions GLOBAL_QUALIFY_LIST.txt
Expand Up @@ -90,6 +90,8 @@
* std::execution::par[link /reference/execution/execution/execution_policy.md]
* std::execution::par_unseq[link /reference/execution/execution/execution_policy.md]
* std::execution::seq[link /reference/execution/execution/execution_policy.md]
* <expected>[link /reference/expected.md]
* std::expected[link /reference/expected/expected.md]
* <filesystem>[link /reference/filesystem.md]
* fe.what()[link /reference/filesystem/filesystem_error/what.md]
* fs::filesystem_error[link /reference/filesystem/filesystem_error.md]
Expand Down
2 changes: 1 addition & 1 deletion lang/cpp23.md
Expand Up @@ -115,7 +115,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
- スタックトレースを取得するためのライブラリとして[`<stacktrace>`](/reference/stacktrace.md)を追加
- CとC++の間でのアトミック操作の相互運用のため、C互換ライブラリとして[`<stdatomic.h>`](/reference/stdatomic.h.md)を追加
- 外部から提供されるメモリバッファでストリーム処理を行うライブラリとして[`<spanstream>`](/reference/spanstream.md.nolink)を追加
- 正常値とエラー値のどちらかを持つクラスおよびライブラリとして[`<expected>`](/reference/expected.md.nolink)を追加
- 正常値とエラー値のどちらかを持つクラスおよびライブラリとして[`<expected>`](/reference/expected.md)を追加
- 多次元配列ビューのライブラリとして[`<mdspan>`](/reference/mdspan.md.nolink)を追加
- ノードベースではないソート済みキーによる順序付き連想コンテナのライブラリとして、[`<flat_map>`](/reference/flat_map.md.nolink)[`<flat_set>`](/reference/flat_set.md.nolink)を追加
- 書式指定で出力するライブラリとして[`<print>`](/reference/print.md.nolink)を追加
Expand Down
2 changes: 1 addition & 1 deletion reference.md
Expand Up @@ -63,7 +63,7 @@
| [`<optional>`](/reference/optional.md) | 任意で値を持たせられるオブジェクト | C++17 |
| [`<variant>`](/reference/variant.md) | 候補の型を切り替えながら保持できる記憶域型 | C++17 |
| [`<any>`](/reference/any.md) | あらゆる型の値を保持できる記憶域型 | C++17 |
| [`<expected>`](/reference/expected.md.nolink) | 正常値かエラー値のどちらかを持たせられるオブジェクト | C++23 |
| [`<expected>`](/reference/expected.md) | 正常値かエラー値のどちらかを持たせられるオブジェクト | C++23 |
| [`<type_traits>`](/reference/type_traits.md) | 型特性 | C++11 |
| [`<functional>`](/reference/functional.md) | 関数オブジェクト | |
| [`<memory>`](/reference/memory.md) | メモリ | |
Expand Down
34 changes: 34 additions & 0 deletions reference/expected.md
@@ -0,0 +1,34 @@
# expected
* expected[meta header]
* cpp23[meta cpp]

`<expected>`ヘッダでは、任意の正常値または任意のエラー値のどちらかを持たせられるオブジェクトの型を定義する。


| 名前 | 説明 | 対応バージョン |
|-----------------|----------------|-------|
| [`expected`](expected/expected.md) | 正常値かエラー値を保持するオブジェクト (class template) | C++23 |
| [`unexpected`](expected/unexpected.md.nolink) | エラー値の代入補助クラス (class template) | C++23 |
| [`unexpect_t`](expected/unexpect_t.md.nolink) | エラー値の直接構築を指示するタグ型 (class) | C++23 |
| [`bad_expected_access`](expected/bad_expected_access.md.nolink) | エラー値保持時に正常値へアクセスした場合に発生する例外 (class template) | C++23 |


## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): 16.0
- [GCC](/implementation.md#gcc): 12.1
- [ICC](/implementation.md#icc): ??
- [Visual C++](/implementation.md#visual_cpp): ??


## 関連項目
- [`optional`](optional.md)


## 参照
- [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)
- [P2505R5 Monadic Functions for `std::expected`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2505r5.html)
120 changes: 120 additions & 0 deletions reference/expected/expected.md
@@ -0,0 +1,120 @@
# expected
* expected[meta header]
* class template[meta id-type]
* std[meta namespace]
* cpp23[meta cpp]

```cpp
namespace std {
template<class T, class E>
class expected;

// T=cv void 部分特殊化
template<class T, class E>
requires is_void_v<T>
class expected<T, E>;
}
```
## 概要
`expected`クラスは、任意の型`T`の値を正常値とし任意の型`E`の値をエラー値として、正常もしくはエラーいずれかの状態を取ることを値として表現できる型である。
## 適格要件
- 型`T`が(CV修飾された)`void`型でなければ、型`T`はCpp17Destructible要件を満たすこと。
- 型`E`はCpp17Destructible要件を満たすこと。
## メンバ関数
### 構築・破棄
| 名前 | 説明 | 対応バージョン |
|-----------------|----------------|-------|
| [`(constructor)`](expected/op_constructor.md.nolink) | コンストラクタ | C++23 |
| [`(destructor)`](expected/op_destructor.md.nolink) | デストラクタ | C++23 |
### 代入
| 名前 | 説明 | 対応バージョン |
|-----------------|----------------|-------|
| [`operator=`](expected/op_assign.md.nolink) | 代入演算子 | C++23 |
| [`emplace`](expected/emplace.md.nolink) | 正常値型のコンストラクタ引数から直接構築する | C++23 |
| [`swap`](expected/swap.md.nolink) | 他の`expected`オブジェクトとデータを入れ替える | C++23 |
### 値の観測
| 名前 | 説明 | 対応バージョン |
|-----------------|----------------|-------|
| [`operator->`](expected/op_arrow.md.nolink) | メンバアクセス | C++23 |
| [`operator*`](expected/op_deref.md.nolink) | 間接参照 | C++23 |
| [`operator bool`](expected/op_bool.md.nolink) | 正常値を保持しているかを判定する | C++23 |
| [`has_value`](expected/has_value.md.nolink) | 正常値を保持しているかを判定する | C++23 |
| [`value`](expected/value.md.nolink) | 正常値を取得する | C++23 |
| [`error`](expected/error.md.nolink) | エラー値を取得する | C++23 |
| [`value_or`](expected/value_or.md.nolink) | 正常値もしくは指定された値を取得する | C++23 |
### モナド操作
| 名前 | 説明 | 対応バージョン |
|------|------|----------------|
| [`and_then`](expected/and_then.md.nolink) | 正常値に対して関数を適用する | C++23 |
| [`or_else`](expected/or_else.md.nolink) | エラー値に対して関数を適用する | C++23 |
| [`transform`](expected/transform.md.nolink) | 正常値を変換する | C++23 |
| [`transform_error`](expected/transform_error.md.nolink) | エラー値を変換する | C++23 |
### 比較
| 名前 | 説明 | 対応バージョン |
|--------------|------------|-------|
| `operator==` | 等値比較 | C++23 |
| `operator!=` | 非等値比較 | C++23 |
## メンバ型
| 名前 | 説明 | 対応バージョン |
|-------------------|-----------------|-------|
| `value_type` | 正常値の型`T` | C++23 |
| `error_type` | エラー値の型`E` | C++23 |
| `unexpected_type` | [`unexpected<E>`](unexpected.md.nolink) | C++23 |
| `template<class U> rebind` | `expected<U, error_type>` | C++23 |
## 例
```cpp example
#include <expected>
#include <iostream>
int main()
{
int variable = 0;
std::cout << variable << std::endl;
}
```
* std::expected[color ff0000]

### 出力
```
0
```


## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): 16.0
- [GCC](/implementation.md#gcc): 12.1
- [ICC](/implementation.md#icc): ??
- [Visual C++](/implementation.md#visual_cpp): ??


## 関連項目
- [`optional`](/reference/optional/optional.md)


## 参照
- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html)
- [P2505R5 Monadic Functions for `std::expected`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2505r5.html)

0 comments on commit e400d17

Please sign in to comment.