actor-framework
Public Types | Public Member Functions | Static Public Attributes | Related Functions | List of all members
caf::expected< T > Class Template Reference

Represents the result of a computation which can either complete successfully with an instance of type T or fail with an error. More...

#include <expected.hpp>

Collaboration diagram for caf::expected< T >:
Collaboration graph
[legend]

Public Types

using value_type = T
 
using error_type = caf::error
 
template<class U >
using rebind = expected< U >
 

Public Member Functions

template<class U , class = std::enable_if_t<std::is_convertible_v<U, T> || is_error_code_enum_v<U>>>
 expected (U x)
 
 expected (T &&x) noexcept(nothrow_move)
 
 expected (const T &x) noexcept(nothrow_copy)
 
 expected (caf::error e) noexcept
 
 expected (const expected &other) noexcept(nothrow_copy)
 
 expected (expected &&other) noexcept(nothrow_move)
 
template<class... Ts>
 expected (std::in_place_t, Ts &&... xs)
 
expectedoperator= (const expected &other) noexcept(nothrow_copy)
 
expectedoperator= (expected &&other) noexcept(nothrow_move)
 
expectedoperator= (const T &x) noexcept(nothrow_copy)
 
expectedoperator= (T &&x) noexcept(nothrow_move)
 
template<class U >
std::enable_if_t< std::is_convertible_v< U, T >, expected & > operator= (U x)
 
expectedoperator= (caf::error e) noexcept
 
template<class Enum , class = std::enable_if_t<is_error_code_enum_v<Enum>>>
expectedoperator= (Enum code)
 
 operator bool () const noexcept
 
bool has_value () const noexcept
 Returns true if the object holds a value (is engaged).
 
template<class... Args>
std::enable_if_t< std::is_nothrow_constructible_v< T, Args... >, T & > emplace (Args &&... args) noexcept
 
void swap (expected &other) noexcept(nothrow_move &&nothrow_swap)
 
T & value () &
 Returns the contained value. More...
 
const T & value () const &
 Returns the contained value. More...
 
T && value () &&
 Returns the contained value. More...
 
const T && value () const &&
 Returns the contained value. More...
 
template<class U >
value_or (U &&fallback) const &
 Returns the contained value if there is one, otherwise returns fallback.
 
template<class U >
value_or (U &&fallback) &&
 Returns the contained value if there is one, otherwise returns fallback.
 
T & operator* () &noexcept
 
const T & operator* () const &noexcept
 
T && operator* () &&noexcept
 
const T && operator* () const &&noexcept
 
T * operator-> () noexcept
 
const T * operator-> () const noexcept
 
caf::errorerror () &noexcept
 
const caf::errorerror () const &noexcept
 
caf::error && error () &&noexcept
 
const caf::error && error () const &&noexcept
 
template<class F >
auto and_then (F &&f) &
 
template<class F >
auto and_then (F &&f) &&
 
template<class F >
auto and_then (F &&f) const &
 
template<class F >
auto and_then (F &&f) const &&
 
template<class F >
expected or_else (F &&f) &
 
template<class F >
expected or_else (F &&f) &&
 
template<class F >
expected or_else (F &&f) const &
 
template<class F >
expected or_else (F &&f) const &&
 
template<class F >
auto transform (F &&f) &
 
template<class F >
auto transform (F &&f) &&
 
template<class F >
auto transform (F &&f) const &
 
template<class F >
auto transform (F &&f) const &&
 
template<class F >
expected transform_or (F &&f) &
 
template<class F >
expected transform_or (F &&f) &&
 
template<class F >
expected transform_or (F &&f) const &
 
template<class F >
expected transform_or (F &&f) const &&
 

Static Public Attributes

static constexpr bool nothrow_move
 Stores whether move construct and move assign never throw. More...
 
static constexpr bool nothrow_copy
 Stores whether copy construct and copy assign never throw. More...
 
static constexpr bool nothrow_swap = std::is_nothrow_swappable_v<T>
 Stores whether swap() never throws.
 

Related Functions

(Note that these are not member functions.)

template<class T >
auto operator== (const expected< T > &x, const expected< T > &y) -> decltype(*x==*y)
 
template<class T , class U >
auto operator== (const expected< T > &x, const U &y) -> decltype(*x==y)
 
template<class T , class U >
auto operator== (const T &x, const expected< U > &y) -> decltype(x==*y)
 
template<class T >
bool operator== (const expected< T > &x, const error &y)
 
template<class T >
bool operator== (const error &x, const expected< T > &y)
 
template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== (const expected< T > &x, Enum y)
 
template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== (Enum x, const expected< T > &y)
 
template<class T >
auto operator!= (const expected< T > &x, const expected< T > &y) -> decltype(*x==*y)
 
template<class T , class U >
auto operator!= (const expected< T > &x, const U &y) -> decltype(*x==y)
 
template<class T , class U >
auto operator!= (const T &x, const expected< U > &y) -> decltype(x==*y)
 
template<class T >
bool operator!= (const expected< T > &x, const error &y)
 
template<class T >
bool operator!= (const error &x, const expected< T > &y)
 
template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= (const expected< T > &x, Enum y)
 
template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= (Enum x, const expected< T > &y)
 
bool operator== (const expected< void > &x, const expected< void > &y)
 
bool operator!= (const expected< void > &x, const expected< void > &y)
 

Detailed Description

template<class T>
class caf::expected< T >

Represents the result of a computation which can either complete successfully with an instance of type T or fail with an error.

Template Parameters
TThe type of the result.

Member Function Documentation

◆ error() [1/4]

template<class T>
caf::error& caf::expected< T >::error ( ) &
inlinenoexcept

◆ error() [2/4]

template<class T>
const caf::error& caf::expected< T >::error ( ) const &
inlinenoexcept

◆ error() [3/4]

template<class T>
caf::error&& caf::expected< T >::error ( ) &&
inlinenoexcept

◆ error() [4/4]

template<class T>
const caf::error&& caf::expected< T >::error ( ) const &&
inlinenoexcept

◆ operator bool()

template<class T>
caf::expected< T >::operator bool ( ) const
inlineexplicitnoexcept

◆ operator*() [1/4]

template<class T>
T& caf::expected< T >::operator* ( ) &
inlinenoexcept

◆ operator*() [2/4]

template<class T>
const T& caf::expected< T >::operator* ( ) const &
inlinenoexcept

◆ operator*() [3/4]

template<class T>
T&& caf::expected< T >::operator* ( ) &&
inlinenoexcept

◆ operator*() [4/4]

template<class T>
const T&& caf::expected< T >::operator* ( ) const &&
inlinenoexcept

◆ operator->() [1/2]

template<class T>
T* caf::expected< T >::operator-> ( )
inlinenoexcept

◆ operator->() [2/2]

template<class T>
const T* caf::expected< T >::operator-> ( ) const
inlinenoexcept

◆ value() [1/4]

template<class T>
T& caf::expected< T >::value ( ) &
inline

Returns the contained value.

Precondition
has_value() == true.

◆ value() [2/4]

template<class T>
const T& caf::expected< T >::value ( ) const &
inline

Returns the contained value.

Precondition
has_value() == true.

◆ value() [3/4]

template<class T>
T&& caf::expected< T >::value ( ) &&
inline

Returns the contained value.

Precondition
has_value() == true.

◆ value() [4/4]

template<class T>
const T&& caf::expected< T >::value ( ) const &&
inline

Returns the contained value.

Precondition
has_value() == true.

Friends And Related Function Documentation

◆ operator!=() [1/8]

template<class T >
auto operator!= ( const expected< T > &  x,
const expected< T > &  y 
) -> decltype(*x == *y)
related

◆ operator!=() [2/8]

template<class T , class U >
auto operator!= ( const expected< T > &  x,
const U &  y 
) -> decltype(*x == y)
related

◆ operator!=() [3/8]

template<class T , class U >
auto operator!= ( const T &  x,
const expected< U > &  y 
) -> decltype(x == *y)
related

◆ operator!=() [4/8]

template<class T >
bool operator!= ( const expected< T > &  x,
const error y 
)
related

◆ operator!=() [5/8]

template<class T >
bool operator!= ( const error x,
const expected< T > &  y 
)
related

◆ operator!=() [6/8]

template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= ( const expected< T > &  x,
Enum  y 
)
related

◆ operator!=() [7/8]

template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= ( Enum  x,
const expected< T > &  y 
)
related

◆ operator!=() [8/8]

template<class T>
bool operator!= ( const expected< void > &  x,
const expected< void > &  y 
)
related

◆ operator==() [1/8]

template<class T >
auto operator== ( const expected< T > &  x,
const expected< T > &  y 
) -> decltype(*x == *y)
related

◆ operator==() [2/8]

template<class T , class U >
auto operator== ( const expected< T > &  x,
const U &  y 
) -> decltype(*x == y)
related

◆ operator==() [3/8]

template<class T , class U >
auto operator== ( const T &  x,
const expected< U > &  y 
) -> decltype(x == *y)
related

◆ operator==() [4/8]

template<class T >
bool operator== ( const expected< T > &  x,
const error y 
)
related

◆ operator==() [5/8]

template<class T >
bool operator== ( const error x,
const expected< T > &  y 
)
related

◆ operator==() [6/8]

template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== ( const expected< T > &  x,
Enum  y 
)
related

◆ operator==() [7/8]

template<class T , class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== ( Enum  x,
const expected< T > &  y 
)
related

◆ operator==() [8/8]

template<class T>
bool operator== ( const expected< void > &  x,
const expected< void > &  y 
)
related

Member Data Documentation

◆ nothrow_copy

template<class T>
constexpr bool caf::expected< T >::nothrow_copy
static
Initial value:
= std::is_nothrow_copy_constructible_v<T>
&& std::is_nothrow_copy_assignable_v<T>

Stores whether copy construct and copy assign never throw.

◆ nothrow_move

template<class T>
constexpr bool caf::expected< T >::nothrow_move
static
Initial value:
= std::is_nothrow_move_constructible_v<T>
&& std::is_nothrow_move_assignable_v<T>

Stores whether move construct and move assign never throw.


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