Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expected/expected: swap非メンバ関数(#1066)
- Loading branch information
Showing
3 changed files
with
142 additions
and
0 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,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) |
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,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) |