Files
2025-10-25 03:02:53 +03:00

3.1 KiB
Raw Permalink Blame History

[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);

1

#

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.

2

#

Effects: See Table 72.

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;

3

#

Throws: Any exception thrown by the expressions in the Effects.

4

#

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)));

5

#

Effects: Equivalent to x.swap(y).