peelo-result
peelo::result< T, E > Class Template Referencefinal

#include <result.hpp>

Public Types

using value_type = T
using error_type = E

Public Member Functions

 result (const value_type &value)
 result (value_type &&value)
 result (const result &that)
 result (result &&that)
template<class U, class G>
 result (const result< U, G > &that)
 ~result ()
resultoperator= (const result &that)
template<class U, class G>
resultoperator= (const result< U, G > &that)
resultoperator= (result &&that)
constexpr bool has_value () const noexcept
constexpr operator bool () const noexcept
constexpr bool operator! () const noexcept
constexpr value_typevalue () noexcept
const value_typevalue () const noexcept
constexpr value_typeoperator-> () noexcept
constexpr const value_typeoperator-> () const noexcept
constexpr value_typeoperator* () noexcept
constexpr const value_typeoperator* () const noexcept
constexpr error_typeerror () noexcept
constexpr const error_typeerror () const noexcept
template<class U>
value_type value_or (U &&default_value) const
template<class U>
error_type error_or (U &&default_error) const
bool equals (const result &that) const
bool operator== (const result &that) const
bool operator!= (const result &that) const
template<class U, class G>
bool equals (const result< U, G > &that) const
template<class U, class G>
bool operator== (const result< U, G > &that) const
template<class U, class G>
bool operator!= (const result< U, G > &that) const

Static Public Member Functions

template<class... Args>
static result< T, E > ok (Args &&... args)
static result< T, E > error (const error_type &error)
template<class... Args>
static result< T, E > error (Args &&... args)

Detailed Description

template<class T, class E>
class peelo::result< T, E >

Represents result of an operation that might be successful or erroneous.

The result contains either an value or error.

Member Typedef Documentation

◆ error_type

template<class T, class E>
using peelo::result< T, E >::error_type = E

◆ value_type

template<class T, class E>
using peelo::result< T, E >::value_type = T

Constructor & Destructor Documentation

◆ result() [1/5]

template<class T, class E>
peelo::result< T, E >::result ( const value_type & value)
inline

Constructs an successful result with given value.

◆ result() [2/5]

template<class T, class E>
peelo::result< T, E >::result ( value_type && value)
inline

Constructs an successful result with given value.

◆ result() [3/5]

template<class T, class E>
peelo::result< T, E >::result ( const result< T, E > & that)
inline

Copy constructor.

◆ result() [4/5]

template<class T, class E>
peelo::result< T, E >::result ( result< T, E > && that)
inline

Move constructor.

◆ result() [5/5]

template<class T, class E>
template<class U, class G>
peelo::result< T, E >::result ( const result< U, G > & that)
inline

Copy constructor.

◆ ~result()

template<class T, class E>
peelo::result< T, E >::~result ( )
inline

Destructor.

Member Function Documentation

◆ equals() [1/2]

template<class T, class E>
bool peelo::result< T, E >::equals ( const result< T, E > & that) const
inline

Tests whether two results are equal or not.

◆ equals() [2/2]

template<class T, class E>
template<class U, class G>
bool peelo::result< T, E >::equals ( const result< U, G > & that) const
inline

Tests whether two results are equal or not.

◆ error() [1/4]

template<class T, class E>
const error_type & peelo::result< T, E >::error ( ) const
inlineconstexprnoexcept

Accesses error contained in the result. If the result contains value instead of error, expect undefined behavior.

◆ error() [2/4]

template<class T, class E>
error_type & peelo::result< T, E >::error ( )
inlineconstexprnoexcept

Accesses error contained in the result. If the result contains value instead of error, expect undefined behavior.

◆ error() [3/4]

template<class T, class E>
template<class... Args>
result< T, E > peelo::result< T, E >::error ( Args &&... args)
inlinestatic

Constructs an erroneous result from given arguments.

◆ error() [4/4]

template<class T, class E>
result< T, E > peelo::result< T, E >::error ( const error_type & error)
inlinestatic

Constructs an erroneous result with given error.

◆ error_or()

template<class T, class E>
template<class U>
error_type peelo::result< T, E >::error_or ( U && default_error) const
inline

Returns error contained in the result, or given default error if the result contains value instead of error.

◆ has_value()

template<class T, class E>
bool peelo::result< T, E >::has_value ( ) const
inlineconstexprnoexcept

Returns true if this result has an value and false if it has an error.

◆ ok()

template<class T, class E>
template<class... Args>
result< T, E > peelo::result< T, E >::ok ( Args &&... args)
inlinestatic

Constructs an successful result from given arguments.

◆ operator bool()

template<class T, class E>
peelo::result< T, E >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if this result has an value and false if it has an error.

◆ operator!()

template<class T, class E>
bool peelo::result< T, E >::operator! ( ) const
inlineconstexprnoexcept

Returns false if this result has an value and true if it has an error.

◆ operator!=() [1/2]

template<class T, class E>
bool peelo::result< T, E >::operator!= ( const result< T, E > & that) const
inline

Non-equality testing operator.

◆ operator!=() [2/2]

template<class T, class E>
template<class U, class G>
bool peelo::result< T, E >::operator!= ( const result< U, G > & that) const
inline

Non-equality testing operator.

◆ operator*() [1/2]

template<class T, class E>
const value_type & peelo::result< T, E >::operator* ( ) const
inlineconstexprnoexcept

References value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ operator*() [2/2]

template<class T, class E>
value_type & peelo::result< T, E >::operator* ( )
inlineconstexprnoexcept

References value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ operator->() [1/2]

template<class T, class E>
const value_type * peelo::result< T, E >::operator-> ( ) const
inlineconstexprnoexcept

Accesses value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ operator->() [2/2]

template<class T, class E>
value_type * peelo::result< T, E >::operator-> ( )
inlineconstexprnoexcept

Accesses value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ operator=() [1/3]

template<class T, class E>
result & peelo::result< T, E >::operator= ( const result< T, E > & that)
inline

Assignment operator.

◆ operator=() [2/3]

template<class T, class E>
template<class U, class G>
result & peelo::result< T, E >::operator= ( const result< U, G > & that)
inline

Assignment operator.

◆ operator=() [3/3]

template<class T, class E>
result & peelo::result< T, E >::operator= ( result< T, E > && that)
inline

Move operator.

◆ operator==() [1/2]

template<class T, class E>
bool peelo::result< T, E >::operator== ( const result< T, E > & that) const
inline

Equality testing operator.

◆ operator==() [2/2]

template<class T, class E>
template<class U, class G>
bool peelo::result< T, E >::operator== ( const result< U, G > & that) const
inline

Equality testing operator.

◆ value() [1/2]

template<class T, class E>
const value_type & peelo::result< T, E >::value ( ) const
inlinenoexcept

Accesses value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ value() [2/2]

template<class T, class E>
value_type & peelo::result< T, E >::value ( )
inlineconstexprnoexcept

Accesses value contained in the result. If the result contains error instead of value, expect undefined behavior.

◆ value_or()

template<class T, class E>
template<class U>
value_type peelo::result< T, E >::value_or ( U && default_value) const
inline

Returns value contained in the result, or given default value if the result contains error instead of value.


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