Lely core libraries 2.3.4
lely::util::Result< T, E > Class Template Reference

A type capable of representing both the successful and failure result of an operation. More...

#include <result.hpp>

Public Types

using value_type = T
 The value type on success.
 
using error_type = typename error_traits::error_type
 The error type on failure.
 

Public Member Functions

 Result ()=default
 Constructs a successful result with an empty value.
 
 Result (const detail::Success< void > &)
 Constructs a successful result with an empty value. More...
 
template<class U >
 Result (const detail::Success< U > &s)
 Constructs a successful result with the specified value. More...
 
template<class U >
 Result (detail::Success< U > &&s)
 Constructs a successful result with the specified value. More...
 
template<class U >
 Result (const detail::Failure< U > &f)
 Constructs a failure result with the specified error. More...
 
template<class U >
 Result (detail::Failure< U > &&f)
 Constructs a failure result with the specified error. More...
 
template<class U >
 Result (U &&u, typename ::std::enable_if< ::std::is_constructible< value_type, U >::value &&!::std::is_constructible< error_type, U >::value, bool >::type=false)
 Constructs a successful result with value u if U is constructible to value_type and not constructible to error_type.
 
template<class U >
 Result (U &&u, typename ::std::enable_if< !::std::is_constructible< value_type, U >::value &&::std::is_constructible< error_type, U >::value, bool >::type=false)
 Constructs a failure result with error u if U is constructible to error_type and not constructible to value_type.
 
 operator bool () const noexcept
 Check whether *this contains a value (and not a non-zero error).
 
bool has_value () const noexcept
 Returns true if *this contains a value (and not a non-zero error). More...
 
value_typevalue ()
 Returns a reference to the value if *this contains a value, and throws an exception if *this contains a non-zero error.
 
const value_typevalue () const
 Returns a reference to the value if *this contains a value, and throws an exception if *this contains a non-zero error.
 
bool has_error () const noexcept
 Returns true if *this contains a non-zero error. More...
 
error_typeerror () noexcept
 Returns a reference to the error, if any.
 
const error_typeerror () const noexcept
 Returns a reference to the error, if any.
 

Detailed Description

template<class T, class E = ::std::error_code>
class lely::util::Result< T, E >

A type capable of representing both the successful and failure result of an operation.

Definition at line 200 of file result.hpp.

Constructor & Destructor Documentation

◆ Result() [1/5]

template<class T , class E = ::std::error_code>
lely::util::Result< T, E >::Result ( const detail::Success< void > &  )
inline

Constructs a successful result with an empty value.

See also
success()

Definition at line 214 of file result.hpp.

◆ Result() [2/5]

template<class T , class E = ::std::error_code>
template<class U >
lely::util::Result< T, E >::Result ( const detail::Success< U > &  s)
inline

Constructs a successful result with the specified value.

See also
success(T&&)

Definition at line 218 of file result.hpp.

◆ Result() [3/5]

template<class T , class E = ::std::error_code>
template<class U >
lely::util::Result< T, E >::Result ( detail::Success< U > &&  s)
inline

Constructs a successful result with the specified value.

See also
success(T&&)

Definition at line 222 of file result.hpp.

◆ Result() [4/5]

template<class T , class E = ::std::error_code>
template<class U >
lely::util::Result< T, E >::Result ( const detail::Failure< U > &  f)
inline

Constructs a failure result with the specified error.

See also
failure(E&&)

Definition at line 226 of file result.hpp.

◆ Result() [5/5]

template<class T , class E = ::std::error_code>
template<class U >
lely::util::Result< T, E >::Result ( detail::Failure< U > &&  f)
inline

Constructs a failure result with the specified error.

See also
failure(E&&)

Definition at line 230 of file result.hpp.

Member Function Documentation

◆ has_value()

template<class T , class E = ::std::error_code>
bool lely::util::Result< T, E >::has_value ( ) const
inlinenoexcept

Returns true if *this contains a value (and not a non-zero error).

See also
has_error()

Definition at line 265 of file result.hpp.

◆ has_error()

template<class T , class E = ::std::error_code>
bool lely::util::Result< T, E >::has_error ( ) const
inlinenoexcept

Returns true if *this contains a non-zero error.

See also
has_value()

Definition at line 291 of file result.hpp.


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