libhatchet
Loading...
Searching...
No Matches
hxexpected< T, E_ > Class Template Reference

#include <hxexpected.hpp>

Public Types

using error_t = E_
using value_t = T

Public Member Functions

 hxexpected (void)
 hxexpected (hxnil_t)
 hxexpected (const hxexpected &x_) noexcept
 hxexpected (hxexpected &&x_) noexcept
template<typename error_t_ = E_, typename... args_t_, hxenable_if_t< !hxis_hxexpected_< hxremove_cvref_t< error_t_ > >::value, bool > = true>
 hxexpected (error_t_ &&error_, args_t_ &&... args_) noexcept
 ~hxexpected (void)
const T & operator* (void) const
T & operator* (void)
const T * operator-> (void) const
T * operator-> (void)
 operator bool (void) const
hxexpected & operator= (const hxexpected &x_) noexcept
hxexpected & operator= (hxexpected &&x_) noexcept
hxexpected & operator= (hxnil_t)
template<typename U_ = T, hxenable_if_t< !hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&!hxis_same< hxremove_cvref_t< U_ >, E_ >(), bool > = true>
hxexpected & operator= (U_ &&value_) noexcept
bool operator== (const hxexpected &x_) const
bool operator== (hxnil_t) const
bool operator== (const T &value_) const
template<typename self_t_, typename callable_t_>
auto and_then (this self_t_ &&self_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>
template<typename... args_t_>
T & emplace (args_t_ &&... args_) noexcept
bool equal (const hxexpected &x_) const
template<typename self_t_>
auto error (this self_t_ &&self_) -> decltype(hxforward_like< self_t_ >(hxdeclval< E_ & >()))
bool has_value (void) const
hxhash_t hash (void) const
template<typename self_t_, typename callable_t_>
hxexpected or_else (this self_t_ &&self_, callable_t_ &&callable_)
void reset (void) noexcept
void reset (const E_ &error_) noexcept
void swap (hxexpected &x_) noexcept
template<typename self_t_>
auto value (this self_t_ &&self_) -> decltype(hxforward_like< self_t_ >(hxdeclval< T & >()))
template<typename self_t_, typename... args_t_>
T value_or (this self_t_ &&self_, args_t_ &&... args_)

Detailed Description

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
class hxexpected< T, E_ >

hxexpected<T, E=bool> - Holds either a value of type T or an error of type E.

Implements std::expected<T, E>. A false equivalent error means the value is valid and a true equivalent error means the value is uninitialized storage. E defaults to bool.

  • T : The contained value type. Must not be a reference or pointer type. Use hxref<T> for reference or pointer types.
  • E : The error type. Must support static_cast<bool>.

Member Typedef Documentation

◆ error_t

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
using hxexpected< T, E_ >::error_t = E_

error_t - Publishes the error type.

◆ value_t

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
using hxexpected< T, E_ >::value_t = T

value_t - Publishes the contained value type.

Constructor & Destructor Documentation

◆ hxexpected() [1/5]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::hxexpected ( void )
inline

Default constructs an error using E(true).

◆ hxexpected() [2/5]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::hxexpected ( hxnil_t )
inline

Constructs an error from hxnil using E(true).

  • hxnil : The error sentinel.

◆ hxexpected() [3/5]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::hxexpected ( const hxexpected< T, E_ > & x_)
noexcept

Copy constructor.

Copies the state, value or error from x.

◆ hxexpected() [4/5]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::hxexpected ( hxexpected< T, E_ > && x_)
noexcept

Move constructor.

Moves the state, value or error from x.

◆ hxexpected() [5/5]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename error_t_ = E_, typename... args_t_, hxenable_if_t< !hxis_hxexpected_< hxremove_cvref_t< error_t_ > >::value, bool > = true>
hxexpected< T, E_ >::hxexpected ( error_t_ && error_,
args_t_ &&... args_ )
explicitnoexcept

Constructs an hxexpected with error.

If error is false then the value is also constructed by forwarding args. The standard idiom for loading a known value with no error is hxexpected(false, args...).

  • error : An error that converts to bool.
  • args : The args to construct the value from. Must be convertible to T.

◆ ~hxexpected()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::~hxexpected ( void )

Destroys the contained value if non-null.

Member Function Documentation

◆ and_then()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename self_t_, typename callable_t_>
auto hxexpected< T, E_ >::and_then ( this self_t_ && self_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>

Returns the result of calling callable with the contained value when there is no error, otherwise returns hxnil.

Use and_then to return hxptr, hxref or hxexpected.

  • callable : The function to call with the contained value.

◆ emplace()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename... args_t_>
T & hxexpected< T, E_ >::emplace ( args_t_ &&... args_)
noexcept

Constructs the contained value in place from args, clearing the error.

  • args : Arguments forwarded to the constructor of T.

◆ equal()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
bool hxexpected< T, E_ >::equal ( const hxexpected< T, E_ > & x_) const

Returns true if both expected values contain equal values or equal errors.

◆ error()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename self_t_>
auto hxexpected< T, E_ >::error ( this self_t_ && self_) ->decltype(hxforward_like< self_t_ >(hxdeclval< E_ & >()))

Returns a reference to the error with the constness and value category of self.

The expected value must contain an error.

◆ has_value()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
bool hxexpected< T, E_ >::has_value ( void ) const
inline

Returns true if the expected value contains a value.

◆ hash()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxhash_t hxexpected< T, E_ >::hash ( void ) const

Returns the hash of the contained value if non-null, otherwise 31u.

◆ operator bool()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected< T, E_ >::operator bool ( void ) const
inlineexplicit

Returns true if the expected value contains a value.

◆ operator*() [1/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
T & hxexpected< T, E_ >::operator* ( void )

◆ operator*() [2/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
const T & hxexpected< T, E_ >::operator* ( void ) const

Returns a const reference to the contained value.

The expected value must not contain an error.

◆ operator->() [1/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
T * hxexpected< T, E_ >::operator-> ( void )

◆ operator->() [2/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
const T * hxexpected< T, E_ >::operator-> ( void ) const

Returns a const pointer to the contained value.

The expected value must not contain an error.

◆ operator=() [1/4]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected & hxexpected< T, E_ >::operator= ( const hxexpected< T, E_ > & x_)
noexcept

Copy assignment.

Copies the state, value or error from x.

◆ operator=() [2/4]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected & hxexpected< T, E_ >::operator= ( hxexpected< T, E_ > && x_)
noexcept

Move assignment.

Moves the state, value or error from x.

◆ operator=() [3/4]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
hxexpected & hxexpected< T, E_ >::operator= ( hxnil_t )
inline

Assigns a default error using T(true).

  • hxnil : The error sentinel.

◆ operator=() [4/4]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename U_ = T, hxenable_if_t< !hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&!hxis_same< hxremove_cvref_t< U_ >, E_ >(), bool > = true>
hxexpected & hxexpected< T, E_ >::operator= ( U_ && value_)
noexcept

Assigns value, engaging the expected value.

  • value : The value to assign from. Must be convertible to T.

◆ operator==() [1/3]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
bool hxexpected< T, E_ >::operator== ( const hxexpected< T, E_ > & x_) const
inline

Returns true if both expected values contain equal values or equal errors.

  • x : Right hand side expected value.

◆ operator==() [2/3]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
bool hxexpected< T, E_ >::operator== ( const T & value_) const

Returns true if this expected value contains a value equal to value.

  • value : The value to compare against.

◆ operator==() [3/3]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
bool hxexpected< T, E_ >::operator== ( hxnil_t ) const
inline

Returns true if this expected value contains an error.

  • hxnil : The error sentinel.

◆ or_else()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename self_t_, typename callable_t_>
hxexpected hxexpected< T, E_ >::or_else ( this self_t_ && self_,
callable_t_ && callable_ )

Returns this expected value if non-null, otherwise returns the result of calling callable.

  • callable : The function to call when an error is present.

◆ reset() [1/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
void hxexpected< T, E_ >::reset ( const E_ & error_)
noexcept

Changes the error.

A false error engages a default constructed value and a true error destroys any contained value.

  • error : The error determining whether the value is non-null.

◆ reset() [2/2]

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
void hxexpected< T, E_ >::reset ( void )
noexcept

Destroys the contained value and assigns a true error.

◆ swap()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
void hxexpected< T, E_ >::swap ( hxexpected< T, E_ > & x_)
noexcept

Exchanges the values and errors with x.

◆ value()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename self_t_>
auto hxexpected< T, E_ >::value ( this self_t_ && self_) ->decltype(hxforward_like< self_t_ >(hxdeclval< T & >()))

Returns a reference to the contained value with the constness and value category of self.

The expected value must not contain an error.

◆ value_or()

template<hxexpected_concept_ T, hxunexpected_concept_ E_>
template<typename self_t_, typename... args_t_>
T hxexpected< T, E_ >::value_or ( this self_t_ && self_,
args_t_ &&... args_ )

Returns the contained value if non-null, otherwise returns a T constructed from args.

  • args : The arguments used to construct the value when an error is present.

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