ResultOk< T > Class Template Reference

#include <resultbase.h>

Detailed Description

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

Use ResultOk<T> instead of Result<T> as return type of a function which cannot fail, but whose return value will be checked for errors nevertheless. For example, this can happen if the function is overloaded and the other overload may return an error. Now if within a template function the overload in a call is chosen depending on the template arguments, the result has to be checked for an error, so also the function which cannot fail has to return a value which is understood by the error handling.

Public Types

using IsResult = std::true_type
 
using ValueType = T
 

Public Member Functions

 ResultOk ()
 
MAXON_IMPLICIT ResultOk (const T &value)
 
MAXON_IMPLICIT ResultOk (T &&value)
 
const T & GetValue () const &
 
const T & UncheckedGetValue () const &
 
const T & GetValueOr (const T &defaultValue) const
 
T GetValueOr (T &&defaultValue) const
 
const T & GetValueOrDefault () const &
 
void IfErrIgnore (const char *) const
 
 MAXON_MEMBER_ACCESSORS (T, GetValue)
 
 MAXON_MEMBER_ACCESSORS (T, UncheckedGetValue)
 
 MAXON_MEMBER_ACCESSORS (T, GetValueOrDefault)
 
Bool operator== (ERROR_OK ok) const
 
Bool operator== (ERROR_FAILED failed) const
 

Static Public Attributes

static constexpr Bool HAS_ERROR
 

Protected Attributes

T _value
 

Private Member Functions

const ThreadReferencedError & GetErrorStorage () const
 

Member Typedef Documentation

◆ IsResult

using IsResult = std::true_type

◆ ValueType

using ValueType = T

Constructor & Destructor Documentation

◆ ResultOk() [1/3]

ResultOk ( )

Constructs a new ResultOk with a default-constructed value.

◆ ResultOk() [2/3]

MAXON_IMPLICIT ResultOk ( const T &  value)

Constructs a new ResultOk with the given #value.

Parameters
[in]valueThe value to use for the ResultOk.

◆ ResultOk() [3/3]

MAXON_IMPLICIT ResultOk ( T &&  value)

Constructs a new ResultOk with the given #value.

Parameters
[in]valueThe value to use for the ResultOk.

Member Function Documentation

◆ GetValue()

const T& GetValue ( ) const &

Returns the result value.

Returns
Result value.

◆ UncheckedGetValue()

const T& UncheckedGetValue ( ) const &

Returns the result value.

Returns
Result value.

◆ GetValueOr() [1/2]

const T& GetValueOr ( const T &  defaultValue) const

Returns the contained value, or a default value in case of an error.

Parameters
[in]defaultValueDefault value to be used in case of an error.
Returns
Result value.

◆ GetValueOr() [2/2]

T GetValueOr ( T &&  defaultValue) const

Returns the contained value, or a default value in case of an error.

Parameters
[in]defaultValueDefault value to be used in case of an error.
Returns
Result value.

◆ GetValueOrDefault()

const T& GetValueOrDefault ( ) const &

Returns the contained value, or a default value in case of an error.

Returns
Result value.

◆ IfErrIgnore()

void IfErrIgnore ( const char *  ) const

Allows to skip a returned error and to continue execution.

◆ MAXON_MEMBER_ACCESSORS() [1/3]

MAXON_MEMBER_ACCESSORS ( T  ,
GetValue   
)

◆ MAXON_MEMBER_ACCESSORS() [2/3]

MAXON_MEMBER_ACCESSORS ( T  ,
UncheckedGetValue   
)

◆ MAXON_MEMBER_ACCESSORS() [3/3]

MAXON_MEMBER_ACCESSORS ( T  ,
GetValueOrDefault   
)

◆ operator==() [1/2]

Bool operator== ( ERROR_OK  ok) const

Returns always true because a ResultOk never contains an error.

Parameters
[in]okUse the global constant OK.
Returns
Always true.

◆ operator==() [2/2]

Bool operator== ( ERROR_FAILED  failed) const

Returns always false because a ResultOk never contains an error.

Parameters
[in]failedUse the global constant FAILED.
Returns
Always false.

◆ GetErrorStorage()

const ThreadReferencedError& GetErrorStorage ( ) const
private

Member Data Documentation

◆ HAS_ERROR

constexpr Bool HAS_ERROR
staticconstexpr

◆ _value

T _value
protected