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

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::optional::value_or

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

template< class U > constexpr T value_or( U&& value ) const&; |  | (library fundamentals TS)
template< class U > T value_or( U&& value ) &&; |  | (library fundamentals TS)

Returns the contained value if *this is in engaged state, otherwise returns `value`.

### [edit] Parameters

value | - | the value to exchange
Type requirements
- `T` must meet the requirements of `CopyConstructible` in order to use overload (1).
- `T` must meet the requirements of `MoveConstructible` in order to use overload (2).
- `U&&` must be convertible to `T`

### [edit] Return value

The current value if *this is in engaged state, or `value` otherwise.

### [edit] Exceptions

Any exception thrown by the selected constructor of `T`.

If an exception is thrown, the exception safety guarantee is as follows:

- If *this was in engaged state, the contents of the contained value depend on the exception safety guarantee of `T`'s constructor.
- Otherwise, the state of *this does not change. The contents of `value` depend on the exception safety guarantee of `T`'s constructor.

### [edit] See also

value | returns the contained value (public member function) [edit]

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