2.5 KiB
[variant.swap]
22 General utilities library [utilities]
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.
Preconditions: Each Ti meets the Cpp17Swappable requirements ([swappable.requirements]).
Effects:
-
If valueless_by_exception() && rhs.valueless_by_exception() no effect.
-
Otherwise, if index() == rhs.index(), calls swap(GET(*this), GET(rhs)) where i is index().
-
Otherwise, exchanges values of rhs and *this.
Throws: If index() == rhs.index(), any exception thrown by swap(GET(*this), GET(rhs)) with i being index().
Otherwise, any exception thrown by the move constructor of Ti or Tj with i being index() and j being rhs.index().
Remarks: If an exception is thrown during the call to function swap(GET(*this), GET(rhs)), the states of the contained values of *this and of rhs are determined by the exception safety guarantee of swap for lvalues ofTi with i being index().
If an exception is thrown during the exchange of the values of *this and rhs, the states of the values of *this and of rhs are 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.