A sum type representing either a success value or an error. More...
#include <containers.hpp>
Public Member Functions | |
| const E & | error () const |
| Unwrap the error. | |
| bool | is_err () const |
| Check if this result is an error. | |
| bool | is_ok () const |
| Check if this result is a success. | |
| const T & | value () const |
| Unwrap the success value. | |
Static Public Member Functions | |
| static Result | err (E error) |
| Create an error result. | |
| static Result | ok (T value) |
| Create a success result. | |
A sum type representing either a success value or an error.
Inspired by Rust's Result<T, E>. Uses std::variant internally.
| T | The success type. |
| E | The error type (default: std::string). |
Example:
Definition at line 220 of file containers.hpp.
|
inlinestatic |
Create an error result.
| error | The error value. |
Definition at line 234 of file containers.hpp.
References error().
|
inlinenodiscard |
Unwrap the error.
| std::bad_variant_access | if this is a success. |
Definition at line 256 of file containers.hpp.
Referenced by err().
|
inlinenodiscard |
Check if this result is an error.
Definition at line 242 of file containers.hpp.
References is_ok().
|
inlinenodiscard |
Check if this result is a success.
Definition at line 237 of file containers.hpp.
Referenced by is_err().
|
inlinestatic |
Create a success result.
| value | The success value. |
Definition at line 227 of file containers.hpp.
References value().
|
inlinenodiscard |
Unwrap the success value.
| std::bad_variant_access | if this is an error. |
Definition at line 249 of file containers.hpp.
Referenced by ok().