std::expected<T,E>::error_or - cppreference.com (original) (raw)
| template< class G = E > constexpr E error_or( G&& default_value ) const&; | (1) | (since C++23) |
|---|---|---|
| template< class G = E > constexpr E error_or( G&& default_value ) &&; | (2) | (since C++23) |
Returns the unexpected value if it exists, otherwise returns default_value.
[edit] Parameters
| default_value | - | the value to use in case *this does not contain an unexpected value |
|---|---|---|
| Type requirements |
[edit] Return value
has_value() ? std::forward<G>(default_value) : error()
has_value() ? std::forward<G>(default_value) : std::move(error())
[edit] Example
[edit] See also
| | returns the unexpected value (public member function) [edit] | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | returns the expected value if present, another value otherwise (public member function) [edit] |