std::experimental::optional<T>::swap

From cppreference.com
< cpp‎ | experimental‎ | optional
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
void swap( optional& other ) noexcept ( /* see below */ ) ;
(library fundamentals TS)

Swaps the contents with those of other.

  • If neither *this nor other contain a value, the function has no effect.
  • If only one of *this and other contains a value (let's call this object in and the other un), the contained value of un is direct-initialized from std::move(*in) , followed by destruction of the contained value of in as if by in.val->T::~T() . After this call, in does not contain a value un
  • If both *this and other contain values, the contained values are exchanged by calling using std::swap ; swap( **this, *other) . T lvalues 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

See also

specializes the std::swap algorithm
(function)