CppWAMP
C++11 client library for the WAMP protocol
wamp::ErrorOr< T > Class Template Reference

Minimalistic implementation of std::expected<T, std::error_code> More...

#include <cppwamp/erroror.hpp>

Public Types

using value_type = T
 Type representing result values.
 
using error_type = std::error_code
 Type representing errors. *‍/.
 
using ValueType = value_type
 

Public Member Functions

 ErrorOr ()=default
 Default constructor.
 
 ErrorOr (const ErrorOr &)=default
 Copy contructor.
 
 ErrorOr (ErrorOr &&)=default
 Move contructor.
 
 ErrorOr (value_type value)
 Converting constructor taking a value.
 
template<typename G >
 ErrorOr (Unexpected< G > unex)
 Converting constructor taking an Unexpected.
 
template<typename... Args>
value_typeemplace (Args &&... args)
 Initializes the value in-place using the given value constructor arguments.
 
ErrorOroperator= (const ErrorOr &)=default
 Copy assignment.
 
ErrorOroperator= (ErrorOr &&)=default
 Move assignment.
 
ErrorOroperator= (value_type value)
 Value assignment.
 
template<typename G >
ErrorOroperator= (Unexpected< G > unex)
 Error assignment.
 
void swap (ErrorOr &rhs) noexcept(std::is_nothrow_swappable< value_type >::value)
 Swap contents with another instance.
 
value_typeoperator-> ()
 Unchecked access of a member of the stored value.
 
const value_typeoperator-> () const
 Unchecked access of a member of the stored value.
 
value_typeoperator* () &
 Unchecked access of the stored value. More...
 
value_type && operator* () &&
 Unchecked move of the stored value. More...
 
const value_typeoperator* () const &
 Unchecked access of the stored value. More...
 
const value_type && operator* () const &&
 Unchecked move of the stored value. More...
 
 operator bool () const noexcept
 Indicates if a value is being contained.
 
bool has_value () const noexcept
 Indicates if a value is being contained.
 
value_typevalue () &
 Checked access of the stored value. More...
 
value_type && value () &&
 Checked move of the stored value. More...
 
const value_typevalue () const &
 Checked access of the stored value. More...
 
const value_type && value () const &&
 Checked move of the stored value. More...
 
error_typeerror ()
 Unchecked access of the stored error. More...
 
const error_typeerror () const
 Unchecked access of the stored error. More...
 
template<typename U >
value_type value_or (U &&v) const &
 Returns the stored value if it exists, or the given fallback value.
 
template<typename U >
value_type value_or (U &&v) &&
 Returns the moved stored value if it exists, or the given fallback value.
 
Deprecated member functions from old AsyncReult
 ErrorOr (std::error_code ec)
 
 ErrorOr (std::error_code ec, std::string)
 
ValueTypeget ()
 
const ValueTypeget () const
 
std::error_code errorCode () const
 
const std::string & errorInfo () const
 
ErrorOrsetValue (T value)
 
ErrorOrsetError (std::error_code ec)
 
ErrorOrsetError (std::error_code ec, std::string)
 

Related Functions

(Note that these are not member functions.)

template<typename T >
void swap (ErrorOr< T > &x, ErrorOr< T > &y) noexcept(noexcept(x.swap(y)))
 Non-member swap.
 
template<typename T1 , typename T2 >
bool operator== (const ErrorOr< T1 > &x, const ErrorOr< T2 > &y)
 Equality comparison with another ErrorOr.
 
template<typename T1 , typename T2 >
bool operator!= (const ErrorOr< T1 > &x, const ErrorOr< T2 > &y)
 Inequality comparison with another ErrorOr.
 
template<typename T1 , typename T2 >
bool operator== (const ErrorOr< T1 > &x, const T2 &v)
 Equality comparison with a value.
 
template<typename T1 , typename T2 >
bool operator== (const T2 &v, const ErrorOr< T1 > &x)
 Equality comparison with a value.
 
template<typename T1 , typename T2 >
bool operator!= (const ErrorOr< T1 > &x, const T2 &v)
 Inequality comparison with a value.
 
template<typename T1 , typename T2 >
bool operator!= (const T2 &v, const ErrorOr< T1 > &x)
 Inequality comparison with a value.
 
template<typename T , typename E >
bool operator== (const ErrorOr< T > &x, const Unexpected< E > &e)
 Equality comparison with an error.
 
template<typename T , typename E >
bool operator== (const Unexpected< E > &e, const ErrorOr< T > &x)
 Equality comparison with an error.
 
template<typename T , typename E >
bool operator!= (const ErrorOr< T > &x, const Unexpected< E > &e)
 Inequality comparison with an error.
 
template<typename T , typename E >
bool operator!= (const Unexpected< E > &e, const ErrorOr< T > &x)
 Inequality comparison with an error.
 

Detailed Description

template<typename T>
class wamp::ErrorOr< T >

Minimalistic implementation of std::expected<T, std::error_code>

Template Parameters
TThe contained value type when there is no error.
See also
UnexpectedError, AsyncHandler
Examples
examples/asynctimeclient/main.cpp, examples/asynctimeservice/main.cpp, examples/stacklesstimeclient/main.cpp, and examples/stacklesstimeservice/main.cpp.

Member Typedef Documentation

◆ ValueType

template<typename T >
using wamp::ErrorOr< T >::ValueType = value_type

Constructor & Destructor Documentation

◆ ErrorOr() [1/2]

template<typename T >
wamp::ErrorOr< T >::ErrorOr ( std::error_code  ec)
inline
Deprecated:
Use constructor taking an Unexpected.

◆ ErrorOr() [2/2]

template<typename T >
wamp::ErrorOr< T >::ErrorOr ( std::error_code  ec,
std::string   
)
inline
Deprecated:
Use constructor taking an Unexpected.

Member Function Documentation

◆ operator*() [1/4]

template<typename T >
value_type& wamp::ErrorOr< T >::operator* ( ) &
inline

Unchecked access of the stored value.

Precondition
this->has_value() == true

◆ operator*() [2/4]

template<typename T >
value_type&& wamp::ErrorOr< T >::operator* ( ) &&
inline

Unchecked move of the stored value.

Precondition
this->has_value() == true

◆ operator*() [3/4]

template<typename T >
const value_type& wamp::ErrorOr< T >::operator* ( ) const &
inline

Unchecked access of the stored value.

Precondition
this->has_value() == true

◆ operator*() [4/4]

template<typename T >
const value_type&& wamp::ErrorOr< T >::operator* ( ) const &&
inline

Unchecked move of the stored value.

Precondition
this->has_value() == true

◆ value() [1/4]

template<typename T >
value_type& wamp::ErrorOr< T >::value ( ) &
inline

Checked access of the stored value.

Precondition
this->has_value() == true
Exceptions
error::Failureif this->has_value() == false

◆ value() [2/4]

template<typename T >
value_type&& wamp::ErrorOr< T >::value ( ) &&
inline

Checked move of the stored value.

Precondition
this->has_value() == true
Exceptions
error::Failureif this->has_value() == false

◆ value() [3/4]

template<typename T >
const value_type& wamp::ErrorOr< T >::value ( ) const &
inline

Checked access of the stored value.

Precondition
this->has_value() == true
Exceptions
error::Failureif this->has_value() == false

◆ value() [4/4]

template<typename T >
const value_type&& wamp::ErrorOr< T >::value ( ) const &&
inline

Checked move of the stored value.

Precondition
this->has_value() == true
Exceptions
error::Failureif this->has_value() == false

◆ error() [1/2]

template<typename T >
error_type& wamp::ErrorOr< T >::error ( )
inline

Unchecked access of the stored error.

Precondition
this->has_value() == false

◆ error() [2/2]

template<typename T >
const error_type& wamp::ErrorOr< T >::error ( ) const
inline

Unchecked access of the stored error.

Precondition
this->has_value() == false

◆ get() [1/2]

template<typename T >
ValueType& wamp::ErrorOr< T >::get ( )
inline

◆ get() [2/2]

template<typename T >
const ValueType& wamp::ErrorOr< T >::get ( ) const
inline

◆ errorCode()

template<typename T >
std::error_code wamp::ErrorOr< T >::errorCode ( ) const
inline

◆ errorInfo()

template<typename T >
const std::string& wamp::ErrorOr< T >::errorInfo ( ) const
inline
Deprecated:
Additional informational text no longer provided.

◆ setValue()

template<typename T >
ErrorOr& wamp::ErrorOr< T >::setValue ( value)
inline
Deprecated:
Use assignment or ErrorOr::emplace instead.

◆ setError() [1/2]

template<typename T >
ErrorOr& wamp::ErrorOr< T >::setError ( std::error_code  ec)
inline

◆ setError() [2/2]

template<typename T >
ErrorOr& wamp::ErrorOr< T >::setError ( std::error_code  ec,
std::string   
)
inline

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