cpp/utility/optional/swap

Swaps the contents with those of.


 * If neither nor  contain a value, the function has no effect.


 * If only one of and  contains a value (let's call this object  and the other ), the contained value of  is direct-initialized from, followed by destruction of the contained value of  as if by . After this call,  does not contain a value;  contains a value.


 * If both and  contain values, the contained values are exchanged by calling .  lvalues must satisfy.

The program is ill-formed if is.

Return value
(none)

Exceptions
In the case of thrown exception, the states of the contained values of and  are determined by the exception safety guarantees of  of type  or 's move constructor, whichever is called. For both and, if the object contained a value, it is left containing a value, and the other way round.