22 General utilities library [utilities] (original) (raw)
22.6 Variants [variant]
22.6.3 Class template variant [variant.variant]
22.6.3.7 Swap [variant.swap]
constexpr void swap(variant& rhs) noexcept(_see below_);
Mandates: is_move_constructible_v<> is true for all i.
Effects:
- If valueless_by_exception() && rhs.valueless_by_exception() no effect.
- Otherwise, if index() == rhs.index(), calls swap(GET<i>(*this), GET<i>(rhs)) where i is index().
- Otherwise, exchanges values of rhs and *this.
Throws: If index() == rhs.index(), any exception thrown by swap(GET<i>(*this), GET<i>(rhs))with i being index().
Otherwise, any exception thrown by the move constructor of or with i being index() and j being rhs.index().
Remarks: If an exception is thrown during the call to function swap(GET<i>(*this), GET<i>(rhs)), the states of the contained values of *this and of rhs are determined by the exception safety guarantee of swap for lvalues of with i being index().
If an exception is thrown during the exchange of the values of *thisand rhs, the states of the values of *this and of rhsare determined by the exception safety guarantee of variant's move constructor.
The exception specification is equivalent to the logical and ofis_nothrow_move_constructible_v<> && is_nothrow_swappable_v<> for all i.