template<typename RESULT_TYPE>
class maxon::Result< RESULT_TYPE >
The Result class wraps a result value and may also hold an error value. It has to be used for functions or methods which have to indicate that an error happened during their execution so that no normal result value could be computed:
Result<Int> Func()
{
if (everything ok)
return 123;
else
}
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
Functions which don't return a value on success use Result<void>
as result type and return OK;
as return statement for the successful case. Those functions can also use a ResultMem value in the return statement, this will set an OutOfMemoryError if the ResultMem is false:
Result<void> Func(MyObj*&
ptr)
{
if (some condition)
}
return OK
Definition: apibase.h:2735
ResultMemT< Bool > ResultMem
Definition: apibaseid.h:19
#define NewObj(T,...)
Definition: newobj.h:108
char ** ptr
Definition: pycore_dtoa.h:13
The result value and error can be obtained via GetValue() and GetError(), respectively. To check if there was an error, you can simply write result == OK
or result == FAILED
. There are also the macros iferr and iferr_return which help to write error handling code.
- Warning
- This class is not thread-safe. The Result object just contains a pointer to an Error object and does not increment the reference counter. Instead of storing the result somewhere, use the direct Error class.
In the following example the Result is a member of a class. The Result will keep the pointer to the Error object, but it does not keep it alive.
class Foo
{
private:
Result<void> _result;
public:
Result<void> GetResult()
{
return _result;
}
}
The alternative is to store the error object. The Error object is reference counted and your object of Foo will keep a reference to it, until the object itself is freed. As long as no error is set (GetResult() == OK) will return true.
class Foo
{
private:
Error _err;
public:
Result<void> GetResult()
{
return _err;
}
}
- Template Parameters
-
RESULT_TYPE | Type of result value. |
- See also
- $ref error_result
|
| Result () |
|
MAXON_IMPLICIT | Result (ErrorPtr &error) |
|
MAXON_IMPLICIT | Result (ErrorPtr &&error) |
|
MAXON_IMPLICIT | Result (const ErrorPtr &error) |
|
MAXON_IMPLICIT | Result (const ThreadReferencedError &error) |
|
MAXON_IMPLICIT | Result (typename std::conditional< STD_IS_REPLACEMENT(void, RESULT_TYPE), ResultMem, const volatile DummyParamType & >::type value) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<typename std::add_const<T2>::type>::type> |
MAXON_IMPLICIT | Result (const ResultOk< T2 > &value) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<T2>::type> |
MAXON_IMPLICIT | Result (ResultOk< T2 > &&value) |
|
MAXON_IMPLICIT | Result (typename std::conditional< STD_IS_REPLACEMENT(void, RESULT_TYPE), ResultOk< RESULT_TYPE >, DummyParamType && >::type value) |
|
template<typename T2 > |
MAXON_IMPLICIT | Result (const ResultMemT< T2 > &value, typename std::enable_if< STD_IS_REPLACEMENT(void, typename SFINAEHelper< RESULT_TYPE, T2 >::type), DummyParamType * >::type=(DummyParamType *) nullptr) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<typename std::add_const<T2>::type>::type> |
MAXON_IMPLICIT | Result (const ResultMemT< T2 > &value) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<T2>::type> |
MAXON_IMPLICIT | Result (ResultMemT< T2 > &&value) |
|
template<typename T2 > |
MAXON_IMPLICIT | Result (const ResultRef< T2 > &value, typename std::enable_if< STD_IS_REPLACEMENT(void, typename SFINAEHelper< RESULT_TYPE, T2 >::type), DummyParamType * >::type=(DummyParamType *) nullptr) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<T2&>::type> |
MAXON_IMPLICIT | Result (const ResultRef< T2 > &value) |
|
MAXON_IMPLICIT | Result (typename std::conditional< STD_IS_REPLACEMENT(void, RESULT_TYPE), ERROR_OK, volatile DummyParamType & >::type) |
|
MAXON_IMPLICIT | Result (typename std::conditional< T_IS_ERROR, const DummyParamType &, CopyType >::type value) |
|
MAXON_IMPLICIT | Result (typename std::conditional< T_IS_ERROR, DummyParamType &, MoveType >::type value) |
|
MAXON_IMPLICIT | Result (typename std::conditional< T_IS_ERROR, const DummyParamType &&, DeleteType >::type value)=delete |
|
template<typename T2 , typename = typename std::enable_if<!maxon::HasBaseDetector<typename std::decay<T2>::type::ReferencedType, ErrorInterface>::value, RESULT_TYPE>::type::ReferencedType, typename = typename Super::template ConstructibleFrom<T2>::type> |
MAXON_IMPLICIT | Result (T2 &&value) |
|
template<typename T2 > |
| Result (const Result< T2 > &src, typename std::enable_if< STD_IS_REPLACEMENT(void, typename SFINAEHelper< RESULT_TYPE, T2 >::type), DummyParamType * >::type=(DummyParamType *) nullptr) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<typename std::add_const<T2>::type>::type> |
MAXON_IMPLICIT | Result (const Result< T2 > &src) |
|
template<typename T2 , typename = typename Super::template ConstructibleFrom<T2>::type> |
MAXON_IMPLICIT | Result (Result< T2 > &&src) |
|
template<typename E > |
MAXON_IMPLICIT | Result (E &&error, typename std::enable_if<!T_IS_ERROR, typename std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), DummyParamType * >::type >::type=(DummyParamType *) nullptr) |
|
template<typename T2 > |
| Result (CopyType value, const Result< T2 > &result) |
|
template<typename T2 > |
| Result (MoveType value, const Result< T2 > &result) |
|
template<typename T2 > |
| Result (DeleteType value, const Result< T2 > &result)=delete |
|
template<typename E > |
| Result (CopyType value, E &&error, typename std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), DummyParamType * >::type=(DummyParamType *) nullptr) |
|
template<typename E > |
| Result (MoveType value, E &&error, typename std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), DummyParamType * >::type=(DummyParamType *) nullptr) |
|
template<typename E > |
| Result (DeleteType value, E &&error, typename std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), DummyParamType * >::type=(DummyParamType *) nullptr)=delete |
|
| Result (typename std::conditional< STD_IS_REPLACEMENT(same, typename std::decay< RESULT_TYPE >::type, Bool), volatile DummyParamType &&, Bool >::type)=delete |
|
SFINAEHelper< Error, RESULT_TYPE >::type | GetError () const |
|
MAXON_ATTRIBUTE_FORCE_INLINE const ErrorInterface * | GetErrorPointer () const |
|
template<typename E > |
std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), E >::type | GetError () const |
|
template<typename E > |
std::enable_if< std::remove_reference< E >::type::DirectlyReferencedType::HasBaseDetector::template Check< ErrorInterface >::value &&MAXON_IS_COW_KIND(std::remove_reference< E >::type::Handler::KIND), Bool >::type | HasError () const |
|
Bool | operator== (ERROR_OK ok) const |
|
Bool | operator== (ERROR_FAILED failed) const |
|
void | operator= (typename std::conditional< STD_IS_REPLACEMENT(reference, RESULT_TYPE), RESULT_TYPE, const DummyParamType & >::type)=delete |
|
| ResultBase () |
|
| ResultBase (CopyType value) |
|
| ResultBase (MoveType value) |
|
MAXON_ATTRIBUTE_FORCE_INLINE const T & | GetValue () const & |
|
MAXON_ATTRIBUTE_FORCE_INLINE const T & | UncheckedGetValue () const & |
|
| MAXON_MEMBER_ACCESSORS (T, GetValue) |
|
| MAXON_MEMBER_ACCESSORS (T, UncheckedGetValue) |
|
MAXON_ATTRIBUTE_FORCE_INLINE const T & | GetValueAndError (ThreadReferencedError &error) const & |
|
MAXON_ATTRIBUTE_FORCE_INLINE T | GetValueAndError (ThreadReferencedError &error) && |
|
MAXON_ATTRIBUTE_FORCE_INLINE const T & | GetValueAndError (Error &error) const & |
|
MAXON_ATTRIBUTE_FORCE_INLINE T | GetValueAndError (Error &error) && |
|
MAXON_ATTRIBUTE_FORCE_INLINE const ThreadReferencedError & | GetErrorStorage () const |
|
MAXON_ATTRIBUTE_FORCE_INLINE ThreadReferencedError & | GetErrorStorage () |
|