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

#include <hxref.hpp>

Public Types

using value_type = T&

Public Member Functions

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

Detailed Description

template<typename T>
class hxref< T >

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

Implements std::optional<T&>. The reference is stored as a T* without dynamic allocation. A disengaged reference compares equal to hxnullopt. Assignment rebinds the reference instead of assigning through to the referent, so the post condition is independent of the engaged state. Const is shallow, matching the rebinding behavior. Use hxref<const T> where write through should be prevented. This is weird but so is the standard.

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

Member Typedef Documentation

◆ value_type

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

value_type - Publishes the referenced value type.

Doesn't end with _t because of the standard.

Constructor & Destructor Documentation

◆ hxref() [1/5]

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

Constructs a disengaged hxref.

◆ hxref() [2/5]

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

Constructs a disengaged hxref from hxnullopt.

  • nullopt : The disengaged sentinel.

◆ hxref() [3/5]

template<typename T>
template<typename U_, hxenable_if_t< !hxdetail_::hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, 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/5]

template<typename T>
template<typename U_, hxenable_if_t< !hxis_same< U_, T >::value, bool > = true>
hxref< T >::hxref ( const hxref< U_ > & other_)

Binds a reference by converting the referent of other.

The referent of other must bind to T& without creating a temporary.

  • other : The hxref whose referent to bind.

◆ hxref() [5/5]

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

Binds a reference by converting the value of other.

The referent of other must bind to T& without creating a temporary. Accepts an engaged or disengaged hxoptional<U>.

Member Function Documentation

◆ and_then()

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

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

callable must return an hxoptional. Implements std::optional::and_then.

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

◆ emplace()

template<typename T>
template<typename U_>
T & hxref< T >::emplace ( U_ & value_)

Binds the reference to value, engaging the reference.

value must bind to T& without creating a temporary. Returns the referenced value.

  • value : The lvalue to reference.

◆ has_value()

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

Returns true if the reference is engaged.

◆ operator bool()

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

Returns true if the reference is engaged.

◆ operator*()

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

Returns a reference to the referenced value. The reference must be engaged.

◆ operator->()

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

Returns a pointer to the referenced value. The reference must be engaged.

◆ operator=() [1/2]

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

Disengages the reference.

The referent is not affected.

  • nullopt : The disengaged sentinel.

◆ operator=() [2/2]

template<typename T>
template<typename U_, hxenable_if_t< !hxdetail_::hxis_hxref_< hxremove_cvref_t< U_ > >::value &&!hxdetail_::hxis_hxoptional_< hxremove_cvref_t< U_ > >::value, 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 > & rhs_) const

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

  • rhs : Right-hand side reference.

◆ operator==() [2/3]

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

Returns true if this reference is engaged and its referent equals value.

  • value : The value to compare against.

◆ operator==() [3/3]

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

Returns true if this reference is disengaged.

  • nullopt : The disengaged sentinel.

◆ or_else()

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

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

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

  • callable : The function to call when disengaged.

◆ reset()

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

Disengages the reference. The referent is not affected.

◆ swap()

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

Exchanges the bound pointers with other.

  • other : 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 engaged.

◆ value_or()

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

Returns the referenced 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: