Namespaces
Variants
Views
Actions

cpp/experimental/optional/value or

From cppreference.com
< cpp‎ | experimental‎ | optional
Revision as of 16:55, 1 July 2013 by P12bot (Talk | contribs)

Template:cpp/utility/optional/title Template:cpp/utility/optional/navbar

template< class U >
constexpr T value_or( U&& value ) const&;
(since C++14)
template< class U >
T value_or( U&& value ) &&;
(since C++14)

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

Contents

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

Return value

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

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.

See also

Template:cpp/utility/optional/dsc value