std::variant::swap
std::variant::swap
void swap( variant& rhs ) noexcept(/* see below */); | (1) | (since C++17) |
Swaps two variant
objects.
- if both
*this
andrhs
are valueless by exception, does nothing - otherwise, if both
*this
andrhs
hold the same alternative, callsswap(std::get<i>(*this), std:get<i>(rhs))
wherei
isindex()
. If an exception is thrown, the state of the values depends on the exception safety of the swap function called. - otherwise, exchanges values of
rhs
and*this
. If an exception is thrown, the state of*this
andrhs
depends on exception safety of variant's move constructor.
The behavior is undefined unless lvalues of type T_i
are Swappable
and std::is_move_constructible_v<T_i>
is true
for all T_i
in Types...
.
Parameters
rhs | - | a variant object to swap with |
Return value
(none).
Exceptions
If this->index() == rhs.index()
, may throw any exception thrown by swap(std::get<i>(*this), std::get<i>(rhs))
with i being index().
Otherwise, may throw any exception thrown by the move constructors of the alternatives currently held by *this
and rhs
.
noexcept
specification: noexcept(((std::is_nothrow_move_constructible_v<Types> &&
std::is_nothrow_swappable_v<Types>) && ...))
Example
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/variant/swap