SPH
Public Member Functions | Friends | List of all members
BasicOutcome< TError > Class Template Reference

Expected-like class that does not contain any value. More...

#include <Outcome.h>

Public Member Functions

INLINE BasicOutcome (SuccessTag)
 Constructs object with success (no error) More...
 
INLINE BasicOutcome (FailTag)
 Constructs object with defautl error message. More...
 
INLINE BasicOutcome (const bool value)
 Constructs object from boolean result. More...
 
template<typename T , typename = std::enable_if_t<std::is_constructible<TError, T>::value>>
INLINE BasicOutcome (T &&error)
 Constructs object given error message. More...
 
INLINE bool success () const
 Checks whether the object contains success, i.e. no error is stored. More...
 
INLINE operator bool () const
 Conversion to bool, returning true if no error is stored. More...
 
INLINE bool operator! () const
 Inversion operator. More...
 
INLINE const TError & error () const
 Returns the error message. More...
 
bool operator== (const BasicOutcome &other) const
 Compares two outcomes. More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const BasicOutcome &outcome)
 Prints "success" or error message into the output stream. More...
 
BasicOutcome operator|| (const BasicOutcome &o1, const BasicOutcome &o2)
 Logical 'or' operator, returning SUCCESS if either of the values is a SUCCESS. More...
 
BasicOutcome operator&& (const BasicOutcome &o1, const BasicOutcome &o2)
 Logical 'and' operator, returning SUCCESS if both values are SUCCESS. More...
 

Detailed Description

template<typename TError>
class BasicOutcome< TError >

Expected-like class that does not contain any value.

Either contains "success" (no error), or error message. The error message must be default-constructible.

Definition at line 44 of file Outcome.h.

Constructor & Destructor Documentation

◆ BasicOutcome() [1/4]

template<typename TError >
INLINE BasicOutcome< TError >::BasicOutcome ( SuccessTag  )
inline

Constructs object with success (no error)

Definition at line 50 of file Outcome.h.

◆ BasicOutcome() [2/4]

template<typename TError >
INLINE BasicOutcome< TError >::BasicOutcome ( FailTag  )
inline

Constructs object with defautl error message.

Definition at line 53 of file Outcome.h.

◆ BasicOutcome() [3/4]

template<typename TError >
INLINE BasicOutcome< TError >::BasicOutcome ( const bool  value)
inlineexplicit

Constructs object from boolean result.

If true, reports success, otherwise reports default error message.

Definition at line 59 of file Outcome.h.

◆ BasicOutcome() [4/4]

template<typename TError >
template<typename T , typename = std::enable_if_t<std::is_constructible<TError, T>::value>>
INLINE BasicOutcome< TError >::BasicOutcome ( T &&  error)
inlineexplicit

Constructs object given error message.

Definition at line 67 of file Outcome.h.

Member Function Documentation

◆ error()

template<typename TError >
INLINE const TError& BasicOutcome< TError >::error ( ) const
inline

Returns the error message.

If the object contains success (no error), asserts.

Definition at line 88 of file Outcome.h.

◆ operator bool()

template<typename TError >
INLINE BasicOutcome< TError >::operator bool ( ) const
inlineexplicit

Conversion to bool, returning true if no error is stored.

Definition at line 76 of file Outcome.h.

◆ operator!()

template<typename TError >
INLINE bool BasicOutcome< TError >::operator! ( ) const
inline

Inversion operator.

Definition at line 81 of file Outcome.h.

◆ operator==()

template<typename TError >
bool BasicOutcome< TError >::operator== ( const BasicOutcome< TError > &  other) const
inline

Compares two outcomes.

Outcomes are only considered equal if both are successful or both contain equal error message.

Definition at line 96 of file Outcome.h.

◆ success()

template<typename TError >
INLINE bool BasicOutcome< TError >::success ( ) const
inline

Checks whether the object contains success, i.e. no error is stored.

Definition at line 71 of file Outcome.h.

Friends And Related Function Documentation

◆ operator&&

template<typename TError >
BasicOutcome operator&& ( const BasicOutcome< TError > &  o1,
const BasicOutcome< TError > &  o2 
)
friend

Logical 'and' operator, returning SUCCESS if both values are SUCCESS.

Returns the error message if one of the values contains an error message. If both values contain an error message, they are concatenated.

Definition at line 124 of file Outcome.h.

◆ operator<<

template<typename TError >
std::ostream& operator<< ( std::ostream &  stream,
const BasicOutcome< TError > &  outcome 
)
friend

Prints "success" or error message into the output stream.

Definition at line 101 of file Outcome.h.

◆ operator||

template<typename TError >
BasicOutcome operator|| ( const BasicOutcome< TError > &  o1,
const BasicOutcome< TError > &  o2 
)
friend

Logical 'or' operator, returning SUCCESS if either of the values is a SUCCESS.

If both values contain an error message, they are concatenated.

Definition at line 113 of file Outcome.h.


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