Skip to content

Commit

Permalink
expected/expected: swap非メンバ関数(#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Feb 9, 2023
1 parent d55ed2f commit 31bdb1a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
8 changes: 8 additions & 0 deletions reference/expected/expected.md
Expand Up @@ -130,6 +130,14 @@ namespace std {
| `template<class U> rebind` | `expected<U, error_type>` | C++23 |
## 非メンバ関数
| 名前 | 説明 | 対応バージョン |
|------|------|-------|
| [`swap`](expected/swap_free.md) | 2つの`expected<T, E>`オブジェクトを入れ替える | C++23 |
| [`swap`](expected.void/swap_free.md) | 2つの`expected<cv void, E>`オブジェクトを入れ替える | C++23 |
## 例
```cpp example
#include <expected>
Expand Down
67 changes: 67 additions & 0 deletions reference/expected/expected.void/swap_free.md
@@ -0,0 +1,67 @@
# swap (非メンバ関数)
* expected[meta header]
* function[meta id-type]
* std[meta namespace]
* expected.void[meta class]
* cpp23[meta cpp]

```cpp
// expected<cv void, E>部分特殊化
friend constexpr void swap(expected& x, expected& y)
noexcept(noexcept(x.swap(y)));
```
* swap[link swap.md]
## 概要
2つの`expected`オブジェクトを入れ替える。
## 効果
```cpp
x.swap(y);
```
* swap[link swap.md]


## 戻り値
なし


##
```cpp example
#include <cassert>
#include <expected>

int main()
{
std::expected<void, int> x;
std::expected<void, int> y = std::unexpected{42};
assert(x.has_value() && y.error() == 42);

std::swap(x, y);
assert(x.error() == 42 && y.has_value());
}
```
* std::swap[color ff0000]
* has_value()[link has_value.md]
* error()[link error.md]
* std::unexpected[link ../unexpected.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)
67 changes: 67 additions & 0 deletions reference/expected/expected/swap_free.md
@@ -0,0 +1,67 @@
# swap (非メンバ関数)
* expected[meta header]
* function[meta id-type]
* std[meta namespace]
* expected[meta class]
* cpp23[meta cpp]

```cpp
friend constexpr void swap(expected& x, expected& y)
noexcept(noexcept(x.swap(y)));
```
* swap[link swap.md]
## 概要
2つの`expected`オブジェクトを入れ替える。
## 効果
```cpp
x.swap(y);
```
* swap[link swap.md]


## 戻り値
なし


##
```cpp example
#include <cassert>
#include <expected>
#include <string>

int main()
{
std::expected<int, std::string> x = 42;
std::expected<int, std::string> y = std::unexpected{"ERR"};
assert(x.value() == 42 && y.error() == "ERR");

std::swap(x, y);
assert(x.error() == "ERR" && y.value() == 42);
}
```
* std::swap[color ff0000]
* value()[link value.md]
* error()[link error.md]
* std::unexpected[link ../unexpected.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)

0 comments on commit 31bdb1a

Please sign in to comment.