SysTutorials

Linux Manual Pages › Section 3

stdoptionalswap(3)

std::optional<T>::swap - std::optional<T>::swap

Synopsis

void swap(optional &other) noexcept(/* see below */);
(since C++ 17)

Swaps the contents with those of other.

Parameters

other - the optional object to exchange the contents with

Return value

(none)

Exceptions

noexcept specification: noexcept(std::is_nothrow_move_constructible_v<T> && std::is_nothrow_swappable_v<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

std::swap(std::optional) specializes the std::swap algorithm                          (function) (C++17)