template< class F > constexpr auto transform( F&& f ) &; | (1) | (since C++23) |
template< class F > constexpr auto transform( F&& f ) const&; | (2) | (since C++23) |
template< class F > constexpr auto transform( F&& f ) &&; | (3) | (since C++23) |
template< class F > constexpr auto transform( F&& f ) const&&; | (4) | (since C++23) |
If *this contains an expected value, invokes f and returns a std::expected object that contains its result; otherwise, returns a std::expected object that contains a copy of error().
If T is not (possibly cv-qualified) void, the contained value (**this) is passed as an argument to f; otherwise f takes no argument.
Let U be:
T is not (possibly cv-qualified) void: std::remove_cv_t<std::invoke_result_t<F, decltype(**this)>>; std::remove_cv_t<std::invoke_result_t<F, decltype(std::move(**this))>>; T is possibly cv-qualified void), std::remove_cv_t<std::invoke_result_t<F>>. U must be a valid value type for std::expected. A variable of type U must be constructible from the result of invocation (but does not need to be move-constructible). The return type is std::expected<U, E>.
true
true
| f | - | a suitable function or Callable object whose call signature returns a non-reference type |
A std::expected object containing either the result of f or an error value, as described above.
|
(C++23) | returns the expected itself if it contains an expected value; otherwise, returns an expected containing the transformed unexpected value (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/expected/transform