|
HDK
|
#include <VE_Result.h>
Inheritance diagram for VE_Result< T >:Public Types | |
| using | Base = VE_ResultBase< T, VE_Error > |
Public Member Functions | |
| VE_Result () | |
| VE_Result (T &&t) | |
| VE_Result (VE_Error &&e) | |
| VE_Result (VE_Error::Code c) | |
| T | value () |
Public Member Functions inherited from VE_ResultBase< T, VE_Error > | |
| VE_ResultBase (T &&t) | |
| VE_ResultBase (VE_Error &&e) | |
| bool | ok () const |
| Returns true if we have a valid result. Otherwise, we have an error. More... | |
| T && | unpack () |
| VE_Error && | error () |
| T | peek () |
Static Public Member Functions | |
| static VE_Result< T > | copyFrom (T t) |
Static Public Member Functions inherited from VE_ResultBase< T, VE_Error > | |
| static VE_ResultBase< T, VE_Error > | copyFrom (T t) |
Additional Inherited Members | |
Protected Attributes inherited from VE_ResultBase< T, VE_Error > | |
| std::variant< T, VE_Error > | myItem |
A class to contain either a value or an error. It is meant to provide a value-semantics based approached to error handling, allowing functions to return either a value or an error in the same type.
It currently works with any value type provided it is moveable. Future work could be done to support classes that are copy-able but not moveable, though I think such types are rarer in practice.
Example usage:
VE_Result<SomeType> fooBar() { Usage pattern is generally this:
auto result = functionThatCanError(); if (!result.ok()) // Error can be handled or bubbled up to caller. return result.error();
// Note that this moves the value out of result and so // result must not be accessed again beyond this point. auto payload = result.unpack();
SomeType st(payload);
// Type is automatically converted to Result<Type> return st; }
Definition at line 186 of file VE_Result.h.
Definition at line 189 of file VE_Result.h.
Definition at line 191 of file VE_Result.h.
Definition at line 193 of file VE_Result.h.
Definition at line 194 of file VE_Result.h.
|
inline |
Definition at line 195 of file VE_Result.h.
Definition at line 197 of file VE_Result.h.