- expected[meta header]
- function[meta id-type]
- std[meta namespace]
- expected[meta class]
- cpp23[meta cpp]
friend constexpr void swap(expected& x, expected& y)
noexcept(noexcept(x.swap(y)));
- x.swap(y)[link swap.md]
2つのexpected
オブジェクトを入れ替える。
x.swap(y);
- swap[link swap.md]
なし
#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: 16.0
- GCC: 12.1
- ICC: ??
- Visual C++: ??