[expected.object.swap] (original) (raw)

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:

Table 70 — swap(expected&) effects [tab:expected.object.swap]

equivalent to: using std​::​swap; swap(val, rhs.val);
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>) { 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<T> && is_nothrow_swappable_v<T> &&is_nothrow_move_constructible_v<E> && is_nothrow_swappable_v<E>

friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y)));

Effects: Equivalent to x.swap(y).