ResultRef< T > Class Template Reference

#include <resultbase.h>

详细描述

template<typename T>
class maxon::ResultRef< T >

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

构造函数 & 析构函数文档编制

◆  ResultRef() [1/5]

MAXON_IMPLICIT ResultRef ( T *  value = nullptr )

◆  ResultRef() [2/5]

MAXON_IMPLICIT ResultRef ( T &  value )

◆  ResultRef() [3/5]

MAXON_IMPLICIT ResultRef ( ERROR_FAILED   )

◆  ResultRef() [4/5]

MAXON_IMPLICIT ResultRef ( const ResultRef < T2 > &  src )

◆  ResultRef() [5/5]

MAXON_IMPLICIT ResultRef ( const ResultPtr < T2 > &  src )

成员函数文档编制

◆  operator=()

void operator= ( T &  )
delete

◆  operator==() [1/2]

Bool operator== ( ERROR_OK   ) const

==(ERROR_OK)

==(ERROR_OK)

◆  operator==() [2/2]

Bool operator== ( ERROR_FAILED   ) const

==(ERROR_FAILED)

==(ERROR_FAILED)

◆  GetValue()

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.

返回
Result 值。

◆  UncheckedGetValue()

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).

返回
Result 值。

◆  GetPointer()

T* GetPointer ( ) const

Returns the result pointer.

返回
Result pointer.

◆  operator&()

const ResultPtr <T>& operator& ( ) const

Converts from a ResultRef<T> to a ResultPtr<T>.

注意
Usually it is a really bad idea to overload the address-of operator. But in this case it can't do any harm because ResultRef isn't used in contexts where the normal address-of operator is used. And if & was applied to a ResultRef with the expectation of returning a pointer, the compiler would complain because ResultPtr doesn't mimic pointers at all.
返回
This ResultRef , cast to a ResultPtr.

Member Data Documentation

◆  _value

T* _value private
Int
maxon::Int Int
定义: ge_sys_math.h:62
iferr_return
#define iferr_return
定义: resultbase.h:1434