std::experimental::optional::swap - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::optional::swap

From cppreference.com
< cpp‎ | experimental‎ | optional

void swap( optional& other ); |  | (library fundamentals TS)

Swaps the contents with those of `other`.

- If none of *this and `other` are in engaged states, the function has no effect.

- If only one of *this and `other` is in engaged state (let's call this object `in` and the other `un`), the contained value of `un` is initialized by moving the contained value of `in`, followed by destruction of the contained value of `in`. `in` is in disengaged state and `un` is in engaged state afterwards.

- If both *this and `other` have engaged states, the contained values are exchanged by calling swap(**this, *other).

### [edit] Parameters

other | - | the `optional` object to exchange the contents with

### [edit] Return value

(none)

### [edit] Exceptions

`noexcept` specification:
noexcept(is_nothrow_move_constructible<T>::value &&
noexcept(swap(declval<T&>(), 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 was in engaged state, it is left in engaged state, and the other way round.

### [edit] See also

std::swap(std::experimental::optional) | specializes the std::swap algorithm (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/optional/swap&oldid=68170"
Category:

- conditionally noexcept