friend constexpr void swap(expected& x, expected& y)
noexcept(noexcept(x.swap(y)));
概要
2つのexpected
オブジェクトを入れ替える。
効果
x.swap(y);
戻り値
なし
例
#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);
}
出力
バージョン
言語
- C++23
処理系
- Clang: 16.0 ✅
- GCC: 12.1 ✅
- ICC: ??
- Visual C++: ??