|
constexpr bool | is_ok () const noexcept |
| Returns true if the result is Ok.
|
|
constexpr bool | is_err () const noexcept |
| Returns true if the result is Err.
|
|
T & | unwrap () noexcept |
| Unwraps the value. Aborts if Err.
|
|
const T & | unwrap () const noexcept |
|
E & | unwrap_err () noexcept |
| Unwraps the error. Aborts if Ok.
|
|
const E & | unwrap_err () const noexcept |
|
T | unwrap_or (T default_value) const noexcept |
| Returns value if Ok, else returns default_value.
|
|
template<typename F> |
T | unwrap_or_else (F &&func) const noexcept(noexcept(func())) |
| Returns value if Ok, else calls func().
|
|
T | unwrap_or_default () const noexcept(std::is_nothrow_default_constructible_v< T >) |
| Returns the value if Ok, else returns a default-constructed value. Requires T to be default-constructible.
|
|
T & | expect (const char *msg) noexcept |
| Unwraps the value or aborts with a custom message if Err.
|
|
const T & | expect (const char *msg) const noexcept |
|
E & | expect_err (const char *msg) noexcept |
| Unwraps the error or aborts with a custom message if Ok.
|
|
const E & | expect_err (const char *msg) const noexcept |
|
template<typename Pred> |
bool | is_ok_and (Pred &&pred) const noexcept(noexcept(pred(std::declval< T >()))) |
| Returns true if the result is Ok and the predicate returns true for the value.
|
|
template<typename Pred> |
bool | is_err_and (Pred &&pred) const noexcept(noexcept(pred(std::declval< E >()))) |
| Returns true if the result is Err and the predicate returns true for the error.
|
|
template<typename F, typename U = std::invoke_result_t<F, T>> |
Result< U, E > | map (F &&func) const noexcept(noexcept(func(std::declval< T >()))) |
| Maps the value if Ok, else propagates Err.
|
|
template<typename F, typename E2 = std::invoke_result_t<F, E>> |
Result< T, E2 > | map_err (F &&func) const noexcept(noexcept(func(std::declval< E >()))) |
| Maps the error if Err, else propagates Ok.
|
|
template<typename U, typename F> |
U | map_or (U default_value, F &&func) const |
| Applies a function to the value if Ok, else returns default_value.
|
|
template<typename D, typename F> |
auto | map_or_else (D &&default_fn, F &&func) const |
| Applies a function to the value if Ok, else computes a default with another function.
|
|
template<typename F, typename R = typename std::invoke_result_t<F, T>> |
R | and_then (F &&func) const noexcept(noexcept(func(std::declval< T >()))) |
| Chains another result-producing function if Ok, else propagates Err.
|
|
template<typename R2> |
auto | and_ (R2 &&res) const |
| Returns res if the result is Ok, otherwise returns self.
|
|
template<typename R2> |
auto | or_ (R2 &&res) const |
| Returns res if the result is Err, otherwise returns self.
|
|
template<typename F> |
auto | or_else (F &&op) const |
| Calls op if the result is Err, otherwise returns self.
|
|
template<typename F> |
const Result & | inspect (F &&func) const noexcept(noexcept(func(std::declval< const T & >()))) |
| Calls func(value) if Ok, returns self.
|
|
template<typename F> |
const Result & | inspect_err (F &&func) const noexcept(noexcept(func(std::declval< const E & >()))) |
| Calls func(error) if Err, returns self.
|
|
bool | contains (const T &value) const |
| Returns true if the result is Ok and contains the given value.
|
|
bool | contains_err (const E &error) const |
| Returns true if the result is Err and contains the given error.
|
|
auto | flatten () const |
| Flattens a Result<Result<U, E>, E> into Result<U, E>.
|
|
std::optional< T > | ok () const |
| Returns the value as std::optional if Ok, otherwise std::nullopt.
|
|
std::optional< E > | err () const |
| Returns the error as std::optional if Err, otherwise std::nullopt.
|
|
| ~Result () |
|
| Result (Result &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E >) |
|
Result & | operator= (Result &&other) noexcept(std::is_nothrow_move_assignable_v< T > &&std::is_nothrow_move_assignable_v< E >) |
|
| Result (const Result &other) noexcept(std::is_nothrow_copy_constructible_v< T > &&std::is_nothrow_copy_constructible_v< E >) |
|
Result & | operator= (const Result &other) noexcept(std::is_nothrow_copy_assignable_v< T > &&std::is_nothrow_copy_assignable_v< E >) |
|
template<typename T, typename E>
class cpp_result::Result< T, E >
Result<T, E> - Holds either a value (Ok) or an error (Err).
- Template Parameters
-
Example:
if (r.is_ok())
std::cout << r.unwrap();
Result< void, E > Ok()
Definition result.hpp:1078