Support Class Library
A set of tools providing classes and utility
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
scl::utils::Result< Value, Error > Class Template Reference

#include "Result.h"

Collaboration diagram for scl::utils::Result< Value, Error >:
Collaboration graph
[legend]

Public Types

using value_type = Value
 
using error_type = Error
 
using impl_type = Either< value_type, error_type >
 

Public Member Functions

bool isOk () const
 
bool isErr () const
 
const value_typevalue () const
 
const value_typeget () const
 
const error_typeerror () const
 
 operator bool () const
 
 operator const value_type & () const
 
const value_typeoperator* () const
 
const value_type *const operator-> () const
 
Optional< value_typetoOptional () const
 
Optional< value_typeasOptional () const
 
template<class T = value_type>
Result< T, error_typemap (std::function< T(const value_type &)> mapper) const
 
template<class T = value_type>
Result< T, error_typethen (std::function< T(const value_type &)> mapper) const
 
template<class E = error_type>
Result< value_type, E > mapError (std::function< E(const error_type &)> mapper) const
 
template<class T = value_type, class E = error_type>
Result< T, E > mapBoth (std::function< T(const value_type &)> valueMapper, std::function< E(const error_type &)> errorMapper) const
 
template<class T = value_type, class E = error_type>
Result< T, E > flatMap (std::function< Result< T, E >(const value_type &)> mapper) const
 
template<class T = value_type, class E = error_type>
Result< T, E > andThen (std::function< Result< T, E >(const value_type &)> mapper) const
 
template<class T = value_type, class E = error_type>
Result< T, E > flatMapError (std::function< Result< T, E >(const error_type &)> mapper) const
 
const value_typeokOr (const value_type &value) const
 
const value_typeokOr (std::function< const value_type &()> factory) const
 
const error_typeerrOr (const error_type &error) const
 
const error_typeerrOr (std::function< const error_type &()> factory) const
 
template<class E >
const value_typeokOrThrow (E ex) const
 

Static Public Member Functions

template<class T >
static Result Ok (T &&value)
 
template<class T >
static Result ok (T &&value)
 
template<class... Args>
static Result emplaceOk (Args &&... args)
 
template<class E >
static Result Err (E &&err)
 
template<class E >
static Result err (E &&error)
 
template<class... Args>
static Result emplaceErr (Args &&... args)
 

Protected Member Functions

 Result ()=delete
 
template<class T >
 Result (details::result_value, T &&value)
 
template<class E >
 Result (details::result_error, E &&err)
 

Protected Attributes

impl_type alt
 

Detailed Description

template<class Value, class Error = Placeholder>
class scl::utils::Result< Value, Error >

Definition at line 18 of file Result.h.

Member Typedef Documentation

◆ error_type

template<class Value , class Error = Placeholder>
using scl::utils::Result< Value, Error >::error_type = Error

Definition at line 21 of file Result.h.

◆ impl_type

template<class Value , class Error = Placeholder>
using scl::utils::Result< Value, Error >::impl_type = Either<value_type, error_type>

Definition at line 22 of file Result.h.

◆ value_type

template<class Value , class Error = Placeholder>
using scl::utils::Result< Value, Error >::value_type = Value

Definition at line 20 of file Result.h.

Constructor & Destructor Documentation

◆ Result() [1/3]

template<class Value , class Error = Placeholder>
scl::utils::Result< Value, Error >::Result ( )
protecteddelete

◆ Result() [2/3]

template<class Value , class Error = Placeholder>
template<class T >
scl::utils::Result< Value, Error >::Result ( details::result_value  ,
T &&  value 
)
inlineprotected

Definition at line 30 of file Result.h.

◆ Result() [3/3]

template<class Value , class Error = Placeholder>
template<class E >
scl::utils::Result< Value, Error >::Result ( details::result_error  ,
E &&  err 
)
inlineprotected

Definition at line 34 of file Result.h.

Member Function Documentation

◆ andThen()

template<class Value , class Error = Placeholder>
template<class T = value_type, class E = error_type>
Result<T, E> scl::utils::Result< Value, Error >::andThen ( std::function< Result< T, E >(const value_type &)>  mapper) const
inline

Definition at line 169 of file Result.h.

◆ asOptional()

template<class Value , class Error = Placeholder>
Optional<value_type> scl::utils::Result< Value, Error >::asOptional ( ) const
inline

Definition at line 130 of file Result.h.

◆ emplaceErr()

template<class Value , class Error = Placeholder>
template<class... Args>
static Result scl::utils::Result< Value, Error >::emplaceErr ( Args &&...  args)
inlinestatic

Definition at line 72 of file Result.h.

◆ emplaceOk()

template<class Value , class Error = Placeholder>
template<class... Args>
static Result scl::utils::Result< Value, Error >::emplaceOk ( Args &&...  args)
inlinestatic

Definition at line 52 of file Result.h.

◆ Err()

template<class Value , class Error = Placeholder>
template<class E >
static Result scl::utils::Result< Value, Error >::Err ( E &&  err)
inlinestatic

Definition at line 59 of file Result.h.

◆ err()

template<class Value , class Error = Placeholder>
template<class E >
static Result scl::utils::Result< Value, Error >::err ( E &&  error)
inlinestatic

Definition at line 67 of file Result.h.

◆ error()

template<class Value , class Error = Placeholder>
const error_type& scl::utils::Result< Value, Error >::error ( ) const
inline

Definition at line 99 of file Result.h.

◆ errOr() [1/2]

template<class Value , class Error = Placeholder>
const error_type& scl::utils::Result< Value, Error >::errOr ( const error_type error) const
inline

Definition at line 193 of file Result.h.

◆ errOr() [2/2]

template<class Value , class Error = Placeholder>
const error_type& scl::utils::Result< Value, Error >::errOr ( std::function< const error_type &()>  factory) const
inline

Definition at line 199 of file Result.h.

◆ flatMap()

template<class Value , class Error = Placeholder>
template<class T = value_type, class E = error_type>
Result<T, E> scl::utils::Result< Value, Error >::flatMap ( std::function< Result< T, E >(const value_type &)>  mapper) const
inline

Definition at line 162 of file Result.h.

◆ flatMapError()

template<class Value , class Error = Placeholder>
template<class T = value_type, class E = error_type>
Result<T, E> scl::utils::Result< Value, Error >::flatMapError ( std::function< Result< T, E >(const error_type &)>  mapper) const
inline

Definition at line 174 of file Result.h.

◆ get()

template<class Value , class Error = Placeholder>
const value_type& scl::utils::Result< Value, Error >::get ( ) const
inline

Definition at line 95 of file Result.h.

◆ isErr()

template<class Value , class Error = Placeholder>
bool scl::utils::Result< Value, Error >::isErr ( ) const
inline

Definition at line 83 of file Result.h.

◆ isOk()

template<class Value , class Error = Placeholder>
bool scl::utils::Result< Value, Error >::isOk ( ) const
inline

Definition at line 79 of file Result.h.

◆ map()

template<class Value , class Error = Placeholder>
template<class T = value_type>
Result<T, error_type> scl::utils::Result< Value, Error >::map ( std::function< T(const value_type &)>  mapper) const
inline

Definition at line 135 of file Result.h.

◆ mapBoth()

template<class Value , class Error = Placeholder>
template<class T = value_type, class E = error_type>
Result<T, E> scl::utils::Result< Value, Error >::mapBoth ( std::function< T(const value_type &)>  valueMapper,
std::function< E(const error_type &)>  errorMapper 
) const
inline

Definition at line 154 of file Result.h.

◆ mapError()

template<class Value , class Error = Placeholder>
template<class E = error_type>
Result<value_type, E> scl::utils::Result< Value, Error >::mapError ( std::function< E(const error_type &)>  mapper) const
inline

Definition at line 147 of file Result.h.

◆ Ok()

template<class Value , class Error = Placeholder>
template<class T >
static Result scl::utils::Result< Value, Error >::Ok ( T &&  value)
inlinestatic

Definition at line 39 of file Result.h.

◆ ok()

template<class Value , class Error = Placeholder>
template<class T >
static Result scl::utils::Result< Value, Error >::ok ( T &&  value)
inlinestatic

Definition at line 47 of file Result.h.

◆ okOr() [1/2]

template<class Value , class Error = Placeholder>
const value_type& scl::utils::Result< Value, Error >::okOr ( const value_type value) const
inline

Definition at line 181 of file Result.h.

◆ okOr() [2/2]

template<class Value , class Error = Placeholder>
const value_type& scl::utils::Result< Value, Error >::okOr ( std::function< const value_type &()>  factory) const
inline

Definition at line 187 of file Result.h.

◆ okOrThrow()

template<class Value , class Error = Placeholder>
template<class E >
const value_type& scl::utils::Result< Value, Error >::okOrThrow ( ex) const
inline

Definition at line 206 of file Result.h.

◆ operator bool()

template<class Value , class Error = Placeholder>
scl::utils::Result< Value, Error >::operator bool ( ) const
inline

Definition at line 107 of file Result.h.

◆ operator const value_type &()

template<class Value , class Error = Placeholder>
scl::utils::Result< Value, Error >::operator const value_type & ( ) const
inline

Definition at line 111 of file Result.h.

◆ operator*()

template<class Value , class Error = Placeholder>
const value_type& scl::utils::Result< Value, Error >::operator* ( ) const
inline

Definition at line 115 of file Result.h.

◆ operator->()

template<class Value , class Error = Placeholder>
const value_type* const scl::utils::Result< Value, Error >::operator-> ( ) const
inline

Definition at line 119 of file Result.h.

◆ then()

template<class Value , class Error = Placeholder>
template<class T = value_type>
Result<T, error_type> scl::utils::Result< Value, Error >::then ( std::function< T(const value_type &)>  mapper) const
inline

Definition at line 142 of file Result.h.

◆ toOptional()

template<class Value , class Error = Placeholder>
Optional<value_type> scl::utils::Result< Value, Error >::toOptional ( ) const
inline

Definition at line 124 of file Result.h.

◆ value()

template<class Value , class Error = Placeholder>
const value_type& scl::utils::Result< Value, Error >::value ( ) const
inline

Definition at line 87 of file Result.h.

Member Data Documentation

◆ alt

template<class Value , class Error = Placeholder>
impl_type scl::utils::Result< Value, Error >::alt
protected

Definition at line 25 of file Result.h.


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