SPH
|
Wrapper of type that either contains a value of given type, or an error message. More...
#include <Expected.h>
Public Member Functions | |
Expected () | |
Construct the expected value using default constructor. More... | |
template<typename T , typename = std::enable_if_t<std::is_constructible<Type, T>::value>> | |
Expected (T &&value) | |
Constructs an expected value. More... | |
template<typename TError , typename = std::enable_if_t<std::is_constructible<Error, TError>::value>> | |
Expected (UnexpectedTag, TError &&error) | |
Constructs an unexpected value. More... | |
operator bool () const | |
Conversion to bool, checking whether object constains expected value. More... | |
bool | operator! () const |
Negation operator, returns true if object does NOT contain expected value. More... | |
Type & | value () |
Returns the reference to expected value. More... | |
const Type & | value () const |
Returns the const reference to expected value. More... | |
Type | valueOr (const Type &other) const |
Returns the expected value or given alternative if the object contains unexpected value. More... | |
const Error & | error () const |
Returns the error message. More... | |
Type * | operator-> () |
Operator -> for convenient access to member variables and functions of expected value. More... | |
const Type * | operator-> () const |
operator->() More... | |
Wrapper of type that either contains a value of given type, or an error message.
Expected is designed as a return type. When talking about 'expected' value, it means no error has been encounter and Expected contains value of given type; 'unexpected' value means that Expected contains an error message.
Inspired by Andrei Alexandrescu - Systematic Error Handling in C++ https://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C
Definition at line 25 of file Expected.h.
Construct the expected value using default constructor.
Should be avoided if possible as Expected is mainly designed as a value returned from function, but nevertheless the default constructor is defined for convenience.
Definition at line 40 of file Expected.h.
|
inline |
Constructs an expected value.
Definition at line 46 of file Expected.h.
|
inline |
Constructs an unexpected value.
Definition at line 52 of file Expected.h.
|
inline |
Returns the error message.
Object must contain unexpected value, checked by assert.
Definition at line 94 of file Expected.h.
|
inlineexplicit |
Conversion to bool, checking whether object constains expected value.
Definition at line 57 of file Expected.h.
|
inline |
Negation operator, returns true if object does NOT contain expected value.
Definition at line 62 of file Expected.h.
|
inline |
Operator -> for convenient access to member variables and functions of expected value.
If the object contains unexpected, throws an assert.
Definition at line 102 of file Expected.h.
|
inline |
|
inline |
Returns the reference to expected value.
Object must not contain unexpected value, checked by assert.
Definition at line 69 of file Expected.h.
|
inline |
Returns the const reference to expected value.
Object must not contain unexpected value, checked by assert.
Definition at line 77 of file Expected.h.
|
inline |
Returns the expected value or given alternative if the object contains unexpected value.
Definition at line 83 of file Expected.h.