|
|
Member functions | ||||
Observers | ||||
Monadic operations | ||||
expected::transform_error | ||||
Modifiers | ||||
Non-member functions | ||||
Helper classes | ||||
Primary template | ||
template<class F> constexprauto transform_error( F&& f)&; | (1) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)const&; | (2) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)&&; | (3) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)const&&; | (4) | (since C++23) |
void partial specialization | ||
template<class F> constexprauto transform_error( F&& f)&; | (5) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)const&; | (6) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)&&; | (7) | (since C++23) |
template<class F> constexprauto transform_error( F&& f)const&&; | (8) | (since C++23) |
If*this contains an unexpected value, invokesf with the unexpected value of*this as the argument and returns astd::expected
object that contains an unexpected value, which is initialized with the result off. Otherwise, returns astd::expected
object that represents an expected value.
Given typeG
as:
If any of the following conditions is satisfied, the program is ill-formed:
G
is not a valid template argument forstd::unexpected
.val
))> istrue.val
))> istrue.Contents |
f | - | a suitable function orCallable object whose call signature returns a non-reference type |
Given expressionexpr as:
The return values are defined as follows:
Overload | Value ofhas_value() | |
---|---|---|
true | false | |
(1,2) | std::expected<T, G>(std::in_place, val ) | std::expected<T, G> (std::unexpect, expr) |
(3,4) | std::expected<T, G>(std::in_place, std::move(val )) | |
(5,6) | std::expected<T, G>() | |
(7,8) |
This section is incomplete Reason: no example |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3938 | C++23 | the expected value was obtained byvalue()[1] | changed to**this |
LWG 3973 | C++23 | the expected value was obtained by**this[2] | changed toval |
value()
requiresE
to be copy constructible (seeLWG issue 3843), whereoperator*
does not. returns theexpected itself if it contains an expected value; otherwise, returns the result of the given function on the unexpected value(public member function)[edit] | |
returns anexpected containing the transformed expected value if it exists; otherwise, returns theexpected itself(public member function)[edit] |