Anim 0.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
AnimationSystem::ValueResult< T > Struct Template Reference

Struct representing the return type of a function performing an operation that may fail. Contains a discriminated union of either a success type (specified by T), or an Error state. Allows monadic manipulation of return values from functions using this struct, allowing callers to early return, or take an alternate value, in the case of an error. More...

#include <PureResult.h>

Collaboration diagram for AnimationSystem::ValueResult< T >:

Public Member Functions

bool IsError () const
 
void IgnoreResult () const
 Suppress possible errors in this Result.
 
 ValueResult (T &&entity)
 
 ValueResult (ValueResult const &other)=delete
 
 ValueResult (ValueResult &&other) noexcept
 
 ValueResult (ErrorStruct &&error) noexcept
 
ValueResultoperator= (ValueResult const &other)=delete
 
ValueResultoperator= (ValueResult &&other) noexcept
 
ValueResult< std::monostate > DiscardValue ()
 Converts a ValueResult into a PureResult by dropping any value it held.
 
ErrorStruct const & Error () const
 
ErrorStruct && Error ()
 
void HandleError () const
 Marks ERROR struct has being handled, allowing the struct to safely leave scope without throwing the error.
 
T const & Get () const
 Get the value held by this result. Callers must validate struct contains OK result before calling. More...
 
T && Take ()
 Get the value held by this result. Callers must validate struct contains OK result before calling. More...
 
auto & GetAndUnwrapReference ()
 Get the unwrapped value held by this result when the value is of type std::reference_wrapper. More...
 
T const & GetOrDefault (T const &defaultValue) const
 
T && TakeOrDefault (T &&defaultValue)
 

Static Public Member Functions

static ValueResult OK (T &&entity)
 Factory method creating a ValueResult in the OK state, holding the provided value.
 
static ValueResult< std::monostate > OK ()
 Factory method creating a PureResult (ValueResult<std::monostate>) in the OK state.
 
static ValueResult Error (std::string errorMessage)
 Factory method creating a Result in the Error state.
 
static ValueResult Error (std::string const error, std::exception const &exception)
 Factory method creating a Result in the Error state.
 

Detailed Description

template<class T>
struct AnimationSystem::ValueResult< T >

Struct representing the return type of a function performing an operation that may fail. Contains a discriminated union of either a success type (specified by T), or an Error state. Allows monadic manipulation of return values from functions using this struct, allowing callers to early return, or take an alternate value, in the case of an error.

Template Parameters
TReturn type. If none is desired use PureResult typedef which templated this class with std::monostate.

Member Function Documentation

◆ Error() [1/2]

template<class T >
ErrorStruct && AnimationSystem::ValueResult< T >::Error ( )
inline
Returns
The error in this Result. Calling this on a Result that is OK is forbidden

◆ Error() [2/2]

template<class T >
ErrorStruct const & AnimationSystem::ValueResult< T >::Error ( ) const
inline
Returns
The error in this Result. Calling this on a Result that is OK is forbidden

◆ Get()

template<class T >
T const & AnimationSystem::ValueResult< T >::Get ( ) const
inline

Get the value held by this result. Callers must validate struct contains OK result before calling.

Returns
Gets const ref of result from struct

◆ GetAndUnwrapReference()

template<class T >
auto & AnimationSystem::ValueResult< T >::GetAndUnwrapReference ( )
inline

Get the unwrapped value held by this result when the value is of type std::reference_wrapper.

Returns
Gets const ref of the result of std::reference_wrapper.get() called on the value of this struct

◆ GetOrDefault()

template<class T >
T const & AnimationSystem::ValueResult< T >::GetOrDefault ( T const &  defaultValue) const
inline
Returns
Const ref to result if struct is OK, or returns parameter provided

◆ IsError()

template<class T >
bool AnimationSystem::ValueResult< T >::IsError ( ) const
inline
Returns
If this struct is ERROR, regardless of if the error is handled

◆ Take()

template<class T >
T && AnimationSystem::ValueResult< T >::Take ( )
inline

Get the value held by this result. Callers must validate struct contains OK result before calling.

Returns
Moves result out of struct

◆ TakeOrDefault()

template<class T >
T && AnimationSystem::ValueResult< T >::TakeOrDefault ( T &&  defaultValue)
inline
Returns
Moves result out of struct if struct is OK, or returns parameter provided

The documentation for this struct was generated from the following file: