HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VE_Result< T > Class Template Reference

#include <VE_Result.h>

+ Inheritance diagram for VE_Result< T >:

Public Types

using Base = VE_ResultBase< T, VE_Error >
 

Public Member Functions

 VE_Result ()
 
 VE_Result (T &&t)
 
 VE_Result (VE_Error &&e)
 
 VE_Result (VE_Error::Code c)
 
T value ()
 
- Public Member Functions inherited from VE_ResultBase< T, VE_Error >
 VE_ResultBase (T &&t)
 
 VE_ResultBase (VE_Error &&e)
 
bool ok () const
 Returns true if we have a valid result. Otherwise, we have an error. More...
 
T && unpack ()
 
VE_Error && error ()
 
T peek ()
 

Static Public Member Functions

static VE_Result< TcopyFrom (T t)
 
- Static Public Member Functions inherited from VE_ResultBase< T, VE_Error >
static VE_ResultBase< T, VE_ErrorcopyFrom (T t)
 

Additional Inherited Members

- Protected Attributes inherited from VE_ResultBase< T, VE_Error >
std::variant< T, VE_ErrormyItem
 

Detailed Description

template<typename T>
class VE_Result< T >

A class to contain either a value or an error. It is meant to provide a value-semantics based approached to error handling, allowing functions to return either a value or an error in the same type.

It currently works with any value type provided it is moveable. Future work could be done to support classes that are copy-able but not moveable, though I think such types are rarer in practice.

Example usage:

VE_Result<SomeType> fooBar() { Usage pattern is generally this:

auto result = functionThatCanError(); if (!result.ok()) // Error can be handled or bubbled up to caller. return result.error();

// Note that this moves the value out of result and so // result must not be accessed again beyond this point. auto payload = result.unpack();

SomeType st(payload);

// Type is automatically converted to Result<Type> return st; }

Definition at line 186 of file VE_Result.h.

Member Typedef Documentation

template<typename T>
using VE_Result< T >::Base = VE_ResultBase<T, VE_Error>

Definition at line 189 of file VE_Result.h.

Constructor & Destructor Documentation

template<typename T>
VE_Result< T >::VE_Result ( )
inline

Definition at line 191 of file VE_Result.h.

template<typename T>
VE_Result< T >::VE_Result ( T &&  t)
inline

Definition at line 193 of file VE_Result.h.

template<typename T>
VE_Result< T >::VE_Result ( VE_Error &&  e)
inline

Definition at line 194 of file VE_Result.h.

template<typename T>
VE_Result< T >::VE_Result ( VE_Error::Code  c)
inline

Definition at line 195 of file VE_Result.h.

Member Function Documentation

template<typename T>
static VE_Result<T> VE_Result< T >::copyFrom ( T  t)
inlinestatic

Definition at line 197 of file VE_Result.h.

template<typename T>
T VE_Result< T >::value ( )
inline

Definition at line 199 of file VE_Result.h.


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