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
.
Contents |
[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 ofT
's constructor.
[edit] See also
returns the contained value (public member function) |