Maybe Result
 All Classes Functions
Public Types | Public Member Functions | Static Public Member Functions | List of all members
maybe::result< T, E > Class Template Reference

Public Types

typedef T ok_type
 
typedef E err_type
 

Public Member Functions

 result (T &&value, internal::placeholder)
 
 result (internal::placeholder, E &&value)
 
 result (const T &value, internal::placeholder)
 
 result (internal::placeholder, const E &value)
 
bool is_ok () const noexcept
 
bool is_err () const noexcept
 
 operator bool () const noexcept
 
constexpr T const & ok_value () const &
 
constexpr T & ok_value ()&
 
constexpr T && ok_value ()&&
 
template<class V >
constexpr T ok_value_or (V &&v) const &
 
template<class V >
constexpr T ok_value_or (V &&v)&&
 
constexpr E const & err_value () const &
 
constexpr E & err_value ()&
 
constexpr E && err_value ()&&
 
template<class V >
constexpr E err_value_or (V &&v) const &
 
template<class V >
constexpr E err_value_or (V &&v)&&
 
template<typename F , typename R = typename std::result_of<F(T)>::type>
auto map (F f) noexcept-> maybe::result< R, E >
 
auto map_void () noexcept-> maybe::result< void, E >
 
template<typename U >
auto map_value (U value) noexcept-> maybe::result< U, E >
 
template<typename F >
auto map_err (F f) noexcept-> maybe::result< T, typename std::result_of< F(E)>::type >
 
template<typename U >
auto map_err_value (U value) noexcept-> maybe::result< T, U >
 
template<typename F >
auto and_then (F op) noexcept-> typename std::result_of< F(T)>::type
 
template<typename U >
auto into_err () noexcept-> maybe::result< U, E > const
 

Static Public Member Functions

static constexpr result< T, E > ok (T &&value) noexcept
 
static constexpr result< T, E > ok (const T &value) noexcept
 
static constexpr result< T, E > err (E &&value) noexcept
 
static constexpr result< T, E > err (const E &value) noexcept
 
static constexpr result< T, E > default_ok () noexcept
 
static constexpr result< T, E > default_err () noexcept
 

Detailed Description

template<typename T, typename E>
class maybe::result< T, E >

Definition at line 15 of file result.fwd.hpp.

Member Function Documentation

template<typename T , typename E >
template<typename F >
auto maybe::result< T, E >::and_then ( op) -> typename std::result_of<F(T)>::type
inlinenoexcept

Calls op if the result is ok, otherwise returns the err value of self.

This function can be used for control flow based on result values.

Parameters
fF(T) -> maybe::result<U, E>
Returns
maybe::result<U, E>

Definition at line 73 of file result.inline.hpp.

References maybe::result< T, E >::err().

template<typename T , typename E >
static constexpr result<T, E> maybe::result< T, E >::default_err ( )
inlinestaticnoexcept

Create a new err value using E() constructor.

Returns
result<T, E>

Definition at line 114 of file result.hpp.

template<typename T , typename E >
static constexpr result<T, E> maybe::result< T, E >::default_ok ( )
inlinestaticnoexcept

Create a new ok value using T() constructor.

Returns
result<T, E>

Definition at line 104 of file result.hpp.

Referenced by maybe::result< T, E >::into_err(), and maybe::result< void, E >::into_err().

template<typename T , typename E >
static constexpr result<T, E> maybe::result< T, E >::err ( E &&  value)
inlinestaticnoexcept
template<typename T , typename E >
template<typename U >
auto maybe::result< T, E >::into_err ( ) -> maybe::result<U, E> const
inlinenoexcept

Converts into another result with different ok type U and forwards the same error.

The ok type U must have U() constructor in case the result does not contain an err.

Returns
maybe::result<U, E>

Definition at line 85 of file result.inline.hpp.

References maybe::result< T, E >::default_ok().

template<typename T , typename E >
bool maybe::result< T, E >::is_err ( ) const
inlinenoexcept

Check if result contains err value.

Returns
bool

Definition at line 136 of file result.hpp.

Referenced by maybe::result< void, E >::into_err().

template<typename T , typename E >
bool maybe::result< T, E >::is_ok ( ) const
inlinenoexcept

Check if result contains ok value.

Returns
bool

Definition at line 126 of file result.hpp.

template<typename T , typename E >
template<typename F , typename R >
auto maybe::result< T, E >::map ( f) -> maybe::result<R, E>
inlinenoexcept

Maps a result<T, E> to result<U, E> (where U is return value of F(T)) by applying a function F to a contained ok value, leaving an err value untouched.

This function can be used to compose the results of two functions.

Parameters
fF(T) -> U
Returns
maybe::result<U, E>

Definition at line 17 of file result.inline.hpp.

References maybe::result< T, E >::err().

template<typename T , typename E >
template<typename F >
auto maybe::result< T, E >::map_err ( f) -> maybe::result<T, typename std::result_of<F(E)>::type>
inlinenoexcept

Maps a result<T, E> to result<T, U> (where U is return value of F(E)) by applying a function to a function to a contained err value, leaving an ok value untouched.

This function can be used to pass through a successful result while changing an error.

Parameters
fF(E) -> U
Returns
maybe::result<T, U>

Definition at line 49 of file result.inline.hpp.

template<typename T , typename E >
template<typename U >
auto maybe::result< T, E >::map_err_value ( value) -> maybe::result<T, U>
inlinenoexcept

Maps a result<T, E> to result<T, U> by always returning provided U value on error, leaving an ok value untouched.

This function can be used to compose the results of two functions.

Parameters
valueU
Returns
maybe::result<T, U>

Definition at line 62 of file result.inline.hpp.

References maybe::result< T, E >::err().

template<typename T , typename E >
template<typename U >
auto maybe::result< T, E >::map_value ( value) -> maybe::result<U, E>
inlinenoexcept

Maps a result<T, E> to result<U, E> by always returning provided U value on success, leaving an err value untouched.

This function can be used to compose the results of two functions.

Parameters
valueU
Returns
maybe::result<U, E>

Definition at line 38 of file result.inline.hpp.

References maybe::result< T, E >::err().

template<typename T , typename E >
auto maybe::result< T, E >::map_void ( ) -> maybe::result<void, E>
inlinenoexcept

Maps a result<T, E> to result<void, E>, leaving an err value untouched.

Returns
maybe::result<void, E>

Definition at line 27 of file result.inline.hpp.

References maybe::result< T, E >::err().

template<typename T , typename E >
static constexpr result<T, E> maybe::result< T, E >::ok ( T &&  value)
inlinestaticnoexcept

Create a new ok value.

Parameters
Tvalue
Returns
result<T, E>

Definition at line 71 of file result.hpp.

Referenced by maybe::result< void, E >::map_err_value().


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