3.1 KiB
[expected.object.swap]
22 General utilities library [utilities]
22.8 Expected objects [expected]
22.8.6 Class template expected [expected.expected]
22.8.6.5 Swap [expected.object.swap]
constexpr void swap(expected& rhs) noexcept(see below);
Constraints:
is_swappable_v is true and
is_swappable_v is true and
is_move_constructible_v && is_move_constructible_v is true, and
is_nothrow_move_constructible_v || is_nothrow_move_constructible_v is true.
Table 72 — swap(expected&) effects [tab:expected.object.swap]
| ð | this->has_value() | !this->has_value() |
|---|---|---|
| ð rhs.has_value() |
equivalent to: using std::swap; swap(val, rhs.val); | calls rhs.swap(*this) |
| ð !rhs.has_value() |
see below | equivalent to: using std::swap; swap(unex, rhs.unex); |
For the case where rhs.has_value() is false andthis->has_value() is true, equivalent to:if constexpr (is_nothrow_move_constructible_v) { E tmp(std::move(rhs.unex)); destroy_at(addressof(rhs.unex)); try { construct_at(addressof(rhs.val), std::move(val)); destroy_at(addressof(val)); construct_at(addressof(unex), std::move(tmp)); } catch(...) { construct_at(addressof(rhs.unex), std::move(tmp)); throw; }} else { T tmp(std::move(val)); destroy_at(addressof(val)); try { construct_at(addressof(unex), std::move(rhs.unex)); destroy_at(addressof(rhs.unex)); construct_at(addressof(rhs.val), std::move(tmp)); } catch (...) { construct_at(addressof(val), std::move(tmp)); throw; }}has_val = false; rhs.has_val = true;
Throws: Any exception thrown by the expressions in the Effects.
Remarks: The exception specification is equivalent to:is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && is_nothrow_swappable_v
friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y)));
Effects: Equivalent to x.swap(y).