![]() |
Contur 2
Educational OS kernel simulator
|
A result type that holds either a success value of type T or an ErrorCode. More...
#include <error.h>
Public Member Functions | |
| bool | isOk () const noexcept |
| Returns true if this Result holds a success value. | |
| bool | isError () const noexcept |
| Returns true if this Result holds an error code. | |
| const T & | value () const & |
| Returns a const reference to the success value. | |
| T && | value () && |
| Returns an rvalue reference to the success value (move semantics). | |
| T & | value () & |
| Returns a mutable reference to the success value. | |
| ErrorCode | errorCode () const noexcept |
| Returns the error code. | |
| T | valueOr (T defaultValue) const & |
| Returns the value if ok, or the provided default value if error. | |
Static Public Member Functions | |
| static Result | ok (T value) |
| Constructs a successful Result containing the given value. | |
| static Result | error (ErrorCode code) |
| Constructs a failed Result with the given error code. | |
Private Member Functions | |
| Result (T value) | |
| Result (ErrorCode code) | |
Private Attributes | |
| std::variant< T, ErrorCode > | storage_ |
A result type that holds either a success value of type T or an ErrorCode.
Inspired by Rust's Result<T, E>. Use the static factory methods ok() and error() to construct instances. Check isOk() / isError() before accessing the contained value or error code.
| T | The success value type. |
|
inlineexplicitprivate |
|
inlineexplicitprivate |
|
inlinestaticnodiscard |
Constructs a failed Result with the given error code.
Definition at line 113 of file error.h.
References contur::Ok, and Result().
Referenced by contur::parseRegisterValue(), contur::readFileValue(), contur::validateCommand(), contur::validatePlaybackConfig(), and contur::writeFileValue().
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Returns true if this Result holds an error code.
Definition at line 126 of file error.h.
References storage_.
Referenced by errorCode().
|
inlinenodiscardnoexcept |
|
inlinestaticnodiscard |
Constructs a successful Result containing the given value.
Definition at line 107 of file error.h.
References Result(), and value().
Referenced by contur::parseRegisterValue(), contur::validateCommand(), contur::validatePlaybackConfig(), and contur::writeFileValue().
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
|
private |