auto failure(T &&, ...)

Returns appropriate type sugar for constructing an unsuccessful result or outcome, usually failure_type<EC, EP = void> with a decayed T.

Two default overloads are provided, one taking a single required parameter with optional spare storage value parameter returning failure_type<std::decay_t<T>>, the other taking two required parameters with optional spare storage value parameter returning failure_type<std::decay_t<T>, std::decay_t<U>>. Both overloads perfectly forward their inputs.

Note that failure() overloads are permitted by Outcome to return something other than failure_type. For example, basic_result’s auto as_failure() const & returns whatever type failure() returns, and OUTCOME_TRY(var, expr) by default returns for failure whatever .as_failure() returns. This can be useful to have OUTCOME_TRY(...} propagate on failure something custom for some specific input basic_result or basic_outcome.

Overridable: By Argument Dependent Lookup (ADL).

Requires: Always available.


Header: <outcome/success_failure.hpp>