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