libhatchet
Loading...
Searching...
No Matches
hxoptional< T > Class Template Reference

#include <hxoptional.hpp>

Public Types

using value_type = T

Public Member Functions

 hxoptional (void)
 hxoptional (hxnullopt_t)
 hxoptional (const hxoptional &other_) noexcept
 hxoptional (hxoptional &&other_) noexcept
template<typename U_>
 hxoptional (const hxoptional< U_ > &other_) noexcept
template<typename U_>
 hxoptional (hxoptional< U_ > &&other_) noexcept
template<typename U_ = T, hxenable_if_t< !hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, bool > = true>
 hxoptional (U_ &&value_) noexcept
 ~hxoptional (void)
T & operator* (void)
const T & operator* (void) const
T * operator-> (void)
const T * operator-> (void) const
 operator bool (void) const
hxoptionaloperator= (const hxoptional &other_) noexcept
hxoptionaloperator= (hxoptional &&other_) noexcept
hxoptionaloperator= (hxnullopt_t)
template<typename U_ = T, hxenable_if_t< !hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, bool > = true>
hxoptionaloperator= (U_ &&value_) noexcept
template<typename U_>
hxoptionaloperator= (const hxoptional< U_ > &other_) noexcept
template<typename U_>
hxoptionaloperator= (hxoptional< U_ > &&other_) noexcept
bool operator== (const hxoptional &rhs_) const
bool operator== (hxnullopt_t) const
bool operator== (const T &value_) const
template<typename function_t_>
auto and_then (function_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< T & >()))>
template<typename function_t_>
auto and_then (function_t_ &&callable_) const -> hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< const T & >()))>
template<typename... args_t_>
T & emplace (args_t_ &&... args_) noexcept
bool has_value (void) const
template<typename function_t_>
hxoptional or_else (function_t_ &&callable_) const
void reset (void) noexcept
void swap (hxoptional &other_) noexcept
T & value (void)
const T & value (void) const
template<typename U_ = T>
value_or (U_ &&default_value_) const

Detailed Description

template<typename T>
class hxoptional< T >

hxoptional<T> - Holds either a value of type T or nothing.

Implements std::optional. See hxref for a std::optional<T&> equivalent. The value is stored in aligned internal storage without dynamic allocation. A disengaged optional compares equal to hxnullopt.

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

Member Typedef Documentation

◆ value_type

template<typename T>
using hxoptional< T >::value_type = T

value_type - Publishes the contained value type.

Doesn't end with _t because of the standard.

Constructor & Destructor Documentation

◆ hxoptional() [1/7]

template<typename T>
hxoptional< T >::hxoptional ( void )
inline

Constructs a disengaged hxoptional.

◆ hxoptional() [2/7]

template<typename T>
hxoptional< T >::hxoptional ( hxnullopt_t )
inline

Constructs a disengaged hxoptional from hxnullopt.

  • nullopt : The disengaged sentinel.

◆ hxoptional() [3/7]

template<typename T>
hxoptional< T >::hxoptional ( const hxoptional< T > & other_)
noexcept

Copy constructor.

Copies the engaged state and value from other.

◆ hxoptional() [4/7]

template<typename T>
hxoptional< T >::hxoptional ( hxoptional< T > && other_)
noexcept

Move constructor.

Moves the engaged state and value from other. other is left disengaged.

◆ hxoptional() [5/7]

template<typename T>
template<typename U_>
hxoptional< T >::hxoptional ( const hxoptional< U_ > & other_)
noexcept

Constructs by copying the engaged state and converting the value of other to T.

U must be convertible to T.

◆ hxoptional() [6/7]

template<typename T>
template<typename U_>
hxoptional< T >::hxoptional ( hxoptional< U_ > && other_)
noexcept

Constructs by moving the engaged state and converting the value of other to T.

other is left disengaged. U must be convertible to T.

◆ hxoptional() [7/7]

template<typename T>
template<typename U_ = T, hxenable_if_t< !hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, bool > = true>
hxoptional< T >::hxoptional ( U_ && value_)
noexcept

Constructs an engaged hxoptional by forwarding value into storage.

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

◆ ~hxoptional()

template<typename T>
hxoptional< T >::~hxoptional ( void )
inline

Destroys the contained value if engaged.

Member Function Documentation

◆ and_then() [1/2]

template<typename T>
template<typename function_t_>
auto hxoptional< T >::and_then ( function_t_ && callable_) ->hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< T & >()))>

Returns the result of calling callable with the contained value if engaged, otherwise returns a disengaged optional of the same type.

callable must return an hxoptional.

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

◆ and_then() [2/2]

template<typename T>
template<typename function_t_>
auto hxoptional< T >::and_then ( function_t_ && callable_) const->hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< constT & >()))>

Returns the result of calling callable with the contained value if engaged, otherwise returns a disengaged optional of the same type.

callable must return an hxoptional.

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

◆ emplace()

template<typename T>
template<typename... args_t_>
T & hxoptional< T >::emplace ( args_t_ &&... args_)
noexcept

Constructs the contained value in place from args, destroying any previous value.

  • args : Arguments forwarded to the constructor of T.

◆ has_value()

template<typename T>
bool hxoptional< T >::has_value ( void ) const
inline

Returns true if the optional contains a value.

◆ operator bool()

template<typename T>
hxoptional< T >::operator bool ( void ) const
inline

Returns true if the optional contains a value.

◆ operator*() [1/2]

template<typename T>
T & hxoptional< T >::operator* ( void )

Returns a reference to the contained value.

The optional must be engaged.

◆ operator*() [2/2]

template<typename T>
const T & hxoptional< T >::operator* ( void ) const

Returns a const reference to the contained value.

The optional must be engaged.

◆ operator->() [1/2]

template<typename T>
T * hxoptional< T >::operator-> ( void )

Returns a pointer to the contained value. The optional must be engaged.

◆ operator->() [2/2]

template<typename T>
const T * hxoptional< T >::operator-> ( void ) const

Returns a const pointer to the contained value.

The optional must be engaged.

◆ operator=() [1/6]

template<typename T>
hxoptional & hxoptional< T >::operator= ( const hxoptional< T > & other_)
noexcept

Copy assignment.

Copies the engaged state and value from other.

◆ operator=() [2/6]

template<typename T>
template<typename U_>
hxoptional & hxoptional< T >::operator= ( const hxoptional< U_ > & other_)
noexcept

Copies the engaged state and converts the value of other to T.

U must be convertible to T.

◆ operator=() [3/6]

template<typename T>
hxoptional & hxoptional< T >::operator= ( hxnullopt_t )
inline

Disengages the optional, destroying any contained value.

  • nullopt : The disengaged sentinel.

◆ operator=() [4/6]

template<typename T>
hxoptional & hxoptional< T >::operator= ( hxoptional< T > && other_)
noexcept

Move assignment.

Moves the engaged state and value from other. other is left disengaged.

◆ operator=() [5/6]

template<typename T>
template<typename U_>
hxoptional & hxoptional< T >::operator= ( hxoptional< U_ > && other_)
noexcept

Moves the engaged state and converts the value of other to T.

other is left disengaged. U must be convertible to T.

◆ operator=() [6/6]

template<typename T>
template<typename U_ = T, hxenable_if_t< !hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, bool > = true>
hxoptional & hxoptional< T >::operator= ( U_ && value_)
noexcept

Assigns value by forwarding, engaging the optional.

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

◆ operator==() [1/3]

template<typename T>
bool hxoptional< T >::operator== ( const hxoptional< T > & rhs_) const

Returns true if both optionals are disengaged or both are engaged with equal values.

  • rhs : Right-hand side optional.

◆ operator==() [2/3]

template<typename T>
bool hxoptional< T >::operator== ( const T & value_) const

Returns true if this optional is engaged and its value equals value.

  • value : The value to compare against.

◆ operator==() [3/3]

template<typename T>
bool hxoptional< T >::operator== ( hxnullopt_t ) const
inline

Returns true if this optional is disengaged.

  • nullopt : The disengaged sentinel.

◆ or_else()

template<typename T>
template<typename function_t_>
hxoptional hxoptional< T >::or_else ( function_t_ && callable_) const

Returns a copy of this optional if engaged, otherwise returns the result of calling callable.

callable must return an hxoptional<T>.

  • callable : The function to call when disengaged.

◆ reset()

template<typename T>
void hxoptional< T >::reset ( void )
noexcept

Destroys the contained value if engaged and leaves the optional disengaged.

◆ swap()

template<typename T>
void hxoptional< T >::swap ( hxoptional< T > & other_)
noexcept

Exchanges the contents with other.

Both engaged states and values are swapped.

◆ value() [1/2]

template<typename T>
T & hxoptional< T >::value ( void )

Returns a reference to the contained value.

The optional must be engaged.

◆ value() [2/2]

template<typename T>
const T & hxoptional< T >::value ( void ) const

Returns a const reference to the contained value.

The optional must be engaged.

◆ value_or()

template<typename T>
template<typename U_ = T>
T hxoptional< T >::value_or ( U_ && default_value_) const

Returns the contained value if engaged, otherwise returns default_value forwarded and converted to T.

  • default_value : The value to return when disengaged.

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