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

#include <hxref.hpp>

Public Types

using value_t = T&

Public Member Functions

 hxref (void)
 hxref (hxnil_t)
template<typename U_, hxenable_if_t< !hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&hxbinds_directly< T, U_ >(), bool > = true>
 hxref (U_ &value_)
template<typename E_>
 hxref (hxexpected< T, E_ > &x_)
T & operator* (void) const
T * operator-> (void) const
 operator bool (void) const
hxref & operator= (hxnil_t)
template<typename U_, hxenable_if_t< !hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&hxbinds_directly< T, U_ >(), bool > = true>
hxref & operator= (U_ &value_)
bool operator== (const hxref &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_)(hxdeclval< T & >()))>
bool equal (const hxref &x_) const
bool has_value (void) const
hxhash_t hash (void) const
template<typename self_t_, typename callable_t_>
hxref or_else (this self_t_ &&self_, callable_t_ &&callable_)
void reset (void)
void swap (hxref &x_) noexcept
T & value (void) const
template<typename self_t_, typename... args_t_>
hxremove_cv_t< T > value_or (this self_t_ &&self_, args_t_ &&... args_)

Detailed Description

template<typename T>
class hxref< T >

hxref<T> - Holds a reference to a value of type T, or null.

Implements the non-owning pointer std::optional<T&>. A null reference compares equal to hxnil. Assignment rebinds the reference instead of assigning through to the referent, matching pointer semantics. Use hxref<const T> where write through should be prevented.

  • T : The referenced value type. Must not be an array, reference or pointer type.

Member Typedef Documentation

◆ value_t

template<typename T>
using hxref< T >::value_t = T&

value_type - Publishes the referenced value type.

Doesn't end with _t because of the standard.

Constructor & Destructor Documentation

◆ hxref() [1/4]

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

Constructs a null hxref.

◆ hxref() [2/4]

template<typename T>
hxref< T >::hxref ( hxnil_t )
inline

Constructs a null hxref from hxnil.

  • hxnil : The error sentinel.

◆ hxref() [3/4]

template<typename T>
template<typename U_, hxenable_if_t< !hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&hxbinds_directly< T, U_ >(), bool > = true>
hxref< T >::hxref ( U_ & value_)

Binds a reference to value.

U& must bind to T& without creating a temporary.

  • value : The lvalue to reference.

◆ hxref() [4/4]

template<typename T>
template<typename E_>
hxref< T >::hxref ( hxexpected< T, E_ > & x_)

Binds a reference to the value of x.

Accepts an non-null or erroneous hxexpected<T, E>.

Member Function Documentation

◆ and_then()

template<typename T>
template<typename self_t_, typename callable_t_>
auto hxref< T >::and_then ( this self_t_ && self_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxdeclval< T & >()))>

Returns the result of calling callable with the referenced value if non-null, otherwise returns hxnil.

Use and_then to return hxptr, hxref or hxexpected.

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

◆ equal()

template<typename T>
bool hxref< T >::equal ( const hxref< T > & x_) const

Returns true if both references are null or both reference equal values.

  • x : The hxref to compare against.

◆ has_value()

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

Returns true if the reference is non-null.

◆ hash()

template<typename T>
hxhash_t hxref< T >::hash ( void ) const

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

◆ operator bool()

template<typename T>
hxref< T >::operator bool ( void ) const
inlineexplicit

Returns true if the reference is non-null.

◆ operator*()

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

Returns a reference to the referenced value.

The reference must be non-null.

◆ operator->()

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

Returns a pointer to the referenced value.

The reference must be non-null.

◆ operator=() [1/2]

template<typename T>
hxref & hxref< T >::operator= ( hxnil_t )
inline

Nulls the reference.

The referent is not affected.

  • hxnil : The error sentinel.

◆ operator=() [2/2]

template<typename T>
template<typename U_, hxenable_if_t< !hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxis_hxexpected_< hxremove_cvref_t< U_ > >::value &&hxbinds_directly< T, U_ >(), bool > = true>
hxref & hxref< T >::operator= ( U_ & value_)

Rebinds the reference to value.

  • value : The lvalue to reference.

◆ operator==() [1/3]

template<typename T>
bool hxref< T >::operator== ( const hxref< T > & x_) const
inline

Returns true if both references are null or both reference equal values.

  • x : Right-hand side reference.

◆ operator==() [2/3]

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

Returns true if this reference is non-null and its referent equals value.

  • value : The value to compare against.

◆ operator==() [3/3]

template<typename T>
bool hxref< T >::operator== ( hxnil_t ) const
inline

Returns true if this reference is null.

  • hxnil : The error sentinel.

◆ or_else()

template<typename T>
template<typename self_t_, typename callable_t_>
hxref hxref< T >::or_else ( this self_t_ && self_,
callable_t_ && callable_ )

Returns a copy of this reference if non-null, otherwise returns the result of calling callable.

callable must return an hxref<T>. Implements std::optional::or_else.

  • callable : The function to call when null.

◆ reset()

template<typename T>
void hxref< T >::reset ( void )
inline

Nulls the reference. The referent is not affected.

◆ swap()

template<typename T>
void hxref< T >::swap ( hxref< T > & x_)
noexcept

Exchanges the bound pointers with x.

  • x : The hxref to swap with.

◆ value()

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

Returns a reference to the referenced value.

The reference must be non-null.

◆ value_or()

template<typename T>
template<typename self_t_, typename... args_t_>
hxremove_cv_t< T > hxref< T >::value_or ( this self_t_ && self_,
args_t_ &&... args_ )

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

  • args : The arguments used to construct the value when null.

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