std::expected<T,E>::or_else

If *this contains an unexpected value, invokes f with the unexpected value of *this as the argument and returns its result. Otherwise, returns a std::expected object that represents an expected value.

# Declarations

Primary template
template< class F >
constexpr auto or_else( F&& f ) &;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) const&;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) &&;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) const&&;

(since C++23)

void partial specialization
template< class F >
constexpr auto or_else( F&& f ) &;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) const&;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) &&;

(since C++23)

template< class F >
constexpr auto or_else( F&& f ) const&&;

(since C++23)

# Parameters

# Notes

Feature-test macro Value Std Feature __cpp_lib_expected 202211L (C++23) Monadic functions for std::expected

# Example

This section is incompleteReason: no example

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3938C++23the expected value was obtained by value()[1]changed to **this
LWG 3973C++23the expected value was obtained by **this[2]changed to val

# See also