LibQuicR
quicr::Expected< T, E > Class Template Reference

Holds either a success value or an error value. More...

#include <expected.h>

Public Member Functions

 Expected (const Expected &other)=default
 Copies the contained alternative. More...
 
 Expected (Expected &&other)=default
 Moves the contained alternative. More...
 
template<typename U >
requires std::is_convertible_v< U, T > std::is_convertible_v< U, E > Expected (U &&value)
 Constructs the variant alternative selected by std::variant<T, E>. More...
 
template<typename U >
requires std::is_convertible_v< U, E > Expected (Unexpected< U > &&unex)
 Constructs an error result from an unexpected value. More...
 
constexpr bool has_value () const noexcept
 
constexpr operator bool () const noexcept
 
const T & value () const
 
const E & error () const
 
constexpr const T * operator-> () const noexcept
 

Detailed Description

template<typename T, typename E>
class quicr::Expected< T, E >

Holds either a success value or an error value.

Template Parameters
TSuccess type.
EError type.
Note
This class is not internally synchronized. References and pointers returned by accessors are invalidated when the Expected object is destroyed or moved.
Examples
simple_publish/main.cpp, and simple_subscribe/main.cpp.

Constructor & Destructor Documentation

◆ Expected() [1/4]

template<typename T , typename E >
quicr::Expected< T, E >::Expected ( const Expected< T, E > &  other)
default

Copies the contained alternative.

Parameters
otherResult to copy.

◆ Expected() [2/4]

template<typename T , typename E >
quicr::Expected< T, E >::Expected ( Expected< T, E > &&  other)
default

Moves the contained alternative.

Parameters
otherResult to move.

◆ Expected() [3/4]

template<typename T , typename E >
template<typename U >
requires std::is_convertible_v<U, T> std::is_convertible_v<U, E> quicr::Expected< T, E >::Expected ( U &&  value)
inline

Constructs the variant alternative selected by std::variant<T, E>.

Template Parameters
UType convertible to T or E.
Parameters
valueValue forwarded to the variant.
Exceptions
Anyexception thrown while constructing the selected alternative.

◆ Expected() [4/4]

template<typename T , typename E >
template<typename U >
requires std::is_convertible_v<U, E> quicr::Expected< T, E >::Expected ( Unexpected< U > &&  unex)
inline

Constructs an error result from an unexpected value.

Template Parameters
UError source type convertible to E.
Parameters
unexWrapper whose error is copied into this result.

Member Function Documentation

◆ error()

template<typename T , typename E >
const E& quicr::Expected< T, E >::error ( ) const
inline
Returns
A reference to the error value.
Exceptions
std::bad_variant_accessIf this object contains a success value.

◆ has_value()

template<typename T , typename E >
constexpr bool quicr::Expected< T, E >::has_value ( ) const
inlineconstexprnoexcept
Returns
true when the success alternative is active.

◆ operator bool()

template<typename T , typename E >
constexpr quicr::Expected< T, E >::operator bool ( ) const
inlineexplicitconstexprnoexcept
Returns
The same state reported by has_value().

◆ operator->()

template<typename T , typename E >
constexpr const T* quicr::Expected< T, E >::operator-> ( ) const
inlineconstexprnoexcept
Returns
A pointer to the success value.
Warning
Calling this while the object contains an error terminates the process because the function is noexcept and its internal value access throws.

◆ value()

template<typename T , typename E >
const T& quicr::Expected< T, E >::value ( ) const
inline
Returns
A reference to the success value.
Exceptions
std::bad_variant_accessIf this object contains an error.

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