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

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

# Declarations

# Main template

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

(since C++23)

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

(since C++23)

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

(since C++23)

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

(since C++23)

# void partial specialization

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

(since C++23)

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

(since C++23)

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

(since C++23)

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

(since C++23)

# Parameters

# Notes

Feature-test macroValueStdFeature
__cpp_lib_expected202211LC++23Monadic functions for std::expected

# 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