#include <resultbase.h>
ResultRef<T> wraps a pointer. When the pointer is nullptr, this has to be interpreted as an out-of-memory error condition, otherwise GetValue() returns the pointer as a C++ reference.
ResultRef<T> can be used instead of the more general Result<T&> when only out-of-memory conditions can occur in a function. It will lead to more efficient code.
Sometimes it is necessary to convert a ResultRef<T> to a ResultPtr<T>, for example if the variable to which the result shall be assigned already exists:
BaseArray<Int> array; Int & ref = array.Append() iferr_return ; Int * ptr = ...; if (some condition) { ptr = &array.Append() iferr_return ; }The result of the second call to Append has to be converted from ResultRef<Int> to ResultPtr<Int> so that (in the successful case) #ptr can be set to a pointer to the new array element. For this purpose the address-of operator & is overloaded at ResultRef to do exactly this conversion.
All error handling features of the MAXON API (such as iferr, iferr_return and Result ) support ResultRef .
公共成员函数 |
|
MAXON_IMPLICIT | ResultRef (T *value=nullptr) |
MAXON_IMPLICIT | ResultRef (T &value) |
MAXON_IMPLICIT | ResultRef ( ERROR_FAILED ) |
void | operator= (T &)=delete |
template<typename T2 , typename = typename std::enable_if<(STD_IS_REPLACEMENT(same, const T, const T2) || STD_IS_REPLACEMENT(base_of, T, T2)) && (STD_IS_REPLACEMENT(const, T) >= STD_IS_REPLACEMENT(const, T2))>::type> | |
MAXON_IMPLICIT | ResultRef (const ResultRef < T2 > & src ) |
template<typename T2 , typename = typename std::enable_if<(STD_IS_REPLACEMENT(same, const T, const T2) || STD_IS_REPLACEMENT(base_of, T, T2)) && (STD_IS_REPLACEMENT(const, T) >= STD_IS_REPLACEMENT(const, T2))>::type> | |
MAXON_IMPLICIT | ResultRef (const ResultPtr < T2 > & src ) |
Bool | operator== ( ERROR_OK ) const |
Bool | operator== ( ERROR_FAILED ) const |
T & | GetValue () const |
T & | UncheckedGetValue () const |
T * | GetPointer () const |
const ResultPtr < T > & | operator& () const |
Private Attributes |
|
T * | _value |
MAXON_IMPLICIT ResultRef | ( | T * |
value
=
nullptr
|
) |
MAXON_IMPLICIT ResultRef | ( | T & | value | ) |
MAXON_IMPLICIT ResultRef | ( | ERROR_FAILED | ) |
MAXON_IMPLICIT ResultRef | ( | const ResultRef < T2 > & | src | ) |
MAXON_IMPLICIT ResultRef | ( | const ResultPtr < T2 > & | src | ) |
|
delete |
Bool operator== | ( | ERROR_OK | ) | const |
==(ERROR_OK)
==(ERROR_OK)
Bool operator== | ( | ERROR_FAILED | ) | const |
==(ERROR_FAILED)
==(ERROR_FAILED)
T& GetValue | ( | ) | const |
Returns the result value. This function must not be called when there is no value because an out-of-memory error occurred.
T& UncheckedGetValue | ( | ) | const |
Returns the result value. The result of this function must not be used when there is no value (then it's an invalid C++ reference).
T* GetPointer | ( | ) | const |
Returns the result pointer.
const ResultPtr <T>& operator& | ( | ) | const |
Converts from a ResultRef<T> to a ResultPtr<T>.
T* _value | private |