std::expected<T,E>::and_then
Min standard notice:
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
f: a suitable function or Callable object that returns a std::expected
# Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_expected | 202211L | C++23 | Monadic functions for std::expected |
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3938 | C++23 | the expected value was obtained by value()[1] | changed to **this |
| LWG 3973 | C++23 | the expected value was obtained by **this[2] | changed to val |