|
CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
|
Encapsulates a result that can hold either a value or an Error. More...
#include <CCSDSResult.h>
Public Member Functions | |
| Result (T value) | |
| Constructor for success case. | |
| Result (Error error) | |
| Constructor for failure case. | |
| bool | has_value () const |
| Checks if the result contains a valid value. | |
| T & | value () |
| Retrieves the stored value. | |
| const T & | value () const |
| Error | error () const |
| Retrieves the stored error. | |
| operator bool () const | |
Implicit conversion to bool, allowing usage like if (result). | |
Private Attributes | |
| std::variant< T, Error > | data |
| Holds either a valid value or an Error. | |
Encapsulates a result that can hold either a value or an Error.
This class simplifies error handling by allowing functions to return either a valid result or an Error, reducing the need for exception handling.
| T | The type of value to be stored in the result. |
Definition at line 82 of file CCSDSResult.h.
|
inline |
Constructor for success case.
| value | The successful result value. |
Definition at line 90 of file CCSDSResult.h.
|
inline |
Constructor for failure case.
| error | The Error. |
Definition at line 97 of file CCSDSResult.h.
|
inline |
|
inline |
Checks if the result contains a valid value.
Definition at line 104 of file CCSDSResult.h.
|
inlineexplicit |
Implicit conversion to bool, allowing usage like if (result).
Definition at line 128 of file CCSDSResult.h.
|
inline |
Retrieves the stored value.
has_value() returns true before calling this. Definition at line 113 of file CCSDSResult.h.
|
inline |
Definition at line 114 of file CCSDSResult.h.
|
private |
Holds either a valid value or an Error.
Definition at line 83 of file CCSDSResult.h.