std::experimental::optional<T>::swap
From cppreference.com
void swap( optional& other ) noexcept(/* see below */); |
(library fundamentals TS) | |
Swaps the contents with those of other.
- If neither
*thisnorothercontain a value, the function has no effect.
- If only one of
*thisandothercontains a value (let's call this objectinand the otherun), the contained value ofunis direct-initialized fromstd::move(*in), followed by destruction of the contained value ofinas if byin.val->T::~T(). After this call,indoes not contain a valueuncontains a value.
- If both
*thisandothercontain values, the contained values are exchanged by callingusing std::swap; swap(**this, *other).Tlvalues must satisfy Swappable.
Parameters
| other | - | the optional object to exchange the contents with
|
Return value
(none)
Exceptions
noexcept specification:
noexcept(std::is_nothrow_move_constructible<T>::value && noexcept(swap(std::declval<T&>(), std::declval<T&>())))In the case of thrown exception, the states of the contained values of *this and other are determined by the exception safety guarantees of swap of type T or T's move constructor, whichever is called. For both *this and other, if the object contained a value, it is left containing a value, and the other way round.
See also
| specializes the std::swap algorithm (function) |