libhatchet
Loading...
Searching...
No Matches
hxptr< T, deleter_t_ > Class Template Reference

#include <hxptr.hpp>

Public Types

using element_t = T

Public Member Functions

constexpr hxptr (T *ptr_=0, deleter_t_ deleter_=deleter_t_()) noexcept
constexpr hxptr (hxptr &&other_) noexcept
constexpr ~hxptr (void) noexcept
constexpr hxptroperator= (hxptr &&other_) noexcept
constexpr T & operator* (void) const
constexpr T * operator-> (void) const
constexpr operator bool (void) const
constexpr bool operator== (const hxptr &other_) const
constexpr bool operator== (hxnullptr_t) const
template<typename function_t_>
constexpr auto and_then (function_t_ &&callable_) const -> hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< T & >()))>
constexpr const deleter_t_ & deleter (void) const
constexpr deleter_t_ & deleter (void)
constexpr T * get (void) const
template<typename function_t_>
constexpr hxptr or_else (function_t_ &&callable_) &&
template<typename function_t_>
hxptr or_else (function_t_ &&callable_) const &=delete
constexpr T * release (void)
constexpr void reset (T *ptr_=0) noexcept
constexpr void swap (hxptr &other_) noexcept
template<typename U_ = hxremove_cv_t<T>>
constexpr hxremove_cv_t< T > value_or (U_ &&default_value_) const

Detailed Description

template<typename T, typename deleter_t_ = hxdefault_delete>
class hxptr< T, deleter_t_ >

hxptr<T, deleter_t> - A unique owning pointer.

Owns a single dynamically allocated object of type T and invokes deleter_t on destruction or reset. Only one hxptr may own a given object at a time. Move construction and move assignment transfer ownership. Copy construction and copy assignment are deleted.

  • T : The pointed-to type. Must not be an array, reference or pointer type.
  • deleter_t : A class type invoked as bool deleter(T*) to potentially free the owned pointer. Use hxconsteval_delete for consteval work.

Member Typedef Documentation

◆ element_t

template<typename T, typename deleter_t_ = hxdefault_delete>
using hxptr< T, deleter_t_ >::element_t = T

element_t - Publishes the pointed-to type.

Constructor & Destructor Documentation

◆ hxptr() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ >::hxptr ( T * ptr_ = 0,
deleter_t_ deleter_ = deleter_t_() )
explicitconstexprnoexcept

Constructs an hxptr that takes ownership of ptr with a specific deleter instance.

  • ptr : The pointer to take ownership of. May be null.
  • deleter : Callable with signature bool deleter(T*).

◆ hxptr() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ >::hxptr ( hxptr< T, deleter_t_ > && other_)
constexprnoexcept

Move constructor.

Transfers ownership from other to this. other is left null.

  • other : The hxptr to transfer ownership from.

◆ ~hxptr()

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ >::~hxptr ( void )
constexprnoexcept

Destroys the owned object using deleter_t if non-null.

Member Function Documentation

◆ and_then()

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename function_t_>
auto hxptr< T, deleter_t_ >::and_then ( function_t_ && callable_) const->hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< T & >()))>
constexpr

Returns the result of calling callable with the owned object if non-null, otherwise returns a null hxptr of the same type.

callable must return an hxptr.

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

◆ deleter() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
deleter_t_ & hxptr< T, deleter_t_ >::deleter ( void )
constexpr

Returns a reference to the stored deleter.

◆ deleter() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
const deleter_t_ & hxptr< T, deleter_t_ >::deleter ( void ) const
constexpr

Returns a const reference to the stored deleter.

◆ get()

template<typename T, typename deleter_t_ = hxdefault_delete>
T * hxptr< T, deleter_t_ >::get ( void ) const
inlineconstexpr

Returns the owned pointer without releasing ownership.

◆ operator bool()

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ >::operator bool ( void ) const
constexpr

Returns true if the owned pointer is non-null.

◆ operator*()

template<typename T, typename deleter_t_ = hxdefault_delete>
T & hxptr< T, deleter_t_ >::operator* ( void ) const
constexpr

Returns a reference to the owned object. The pointer must not be null.

◆ operator->()

template<typename T, typename deleter_t_ = hxdefault_delete>
T * hxptr< T, deleter_t_ >::operator-> ( void ) const
constexpr

Returns the owned pointer. The pointer must not be null.

◆ operator=()

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr & hxptr< T, deleter_t_ >::operator= ( hxptr< T, deleter_t_ > && other_)
constexprnoexcept

Move assignment.

Destroys the currently owned object, then transfers ownership from other. other is left null. Self-assignment is not supported.

  • other : The hxptr to transfer ownership from.

◆ operator==() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
bool hxptr< T, deleter_t_ >::operator== ( const hxptr< T, deleter_t_ > & other_) const
constexpr

Returns true if this and other point to the same object.

  • other : The hxptr to compare against.

◆ operator==() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
bool hxptr< T, deleter_t_ >::operator== ( hxnullptr_t ) const
constexpr

Returns true if the owned pointer is null.

◆ or_else() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename function_t_>
hxptr hxptr< T, deleter_t_ >::or_else ( function_t_ && callable_) &&
constexpr

Returns this hxptr moved out if non-null, otherwise returns the result of calling callable.

callable must return an hxptr. Rvalue qualified because ownership is transferred out of this hxptr.

  • callable : The function to call when null.

◆ or_else() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename function_t_>
hxptr hxptr< T, deleter_t_ >::or_else ( function_t_ && callable_) const &
delete

◆ release()

template<typename T, typename deleter_t_ = hxdefault_delete>
T * hxptr< T, deleter_t_ >::release ( void )
constexpr

Releases ownership and returns the previously owned pointer without invoking the deleter.

The caller takes responsibility for freeing it.

◆ reset()

template<typename T, typename deleter_t_ = hxdefault_delete>
void hxptr< T, deleter_t_ >::reset ( T * ptr_ = 0)
constexprnoexcept

Destroys the currently owned object using deleter_t if non-null, then takes ownership of ptr.

  • ptr : The new pointer to own. May be null.

◆ swap()

template<typename T, typename deleter_t_ = hxdefault_delete>
void hxptr< T, deleter_t_ >::swap ( hxptr< T, deleter_t_ > & other_)
constexprnoexcept

Exchanges ownership with other.

Neither pointer is deleted.

  • other : The hxptr to swap with.

◆ value_or()

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename U_ = hxremove_cv_t<T>>
hxremove_cv_t< T > hxptr< T, deleter_t_ >::value_or ( U_ && default_value_) const
constexpr

Returns the owned value if non-null, otherwise returns default_value forwarded and converted to T.

  • default_value : The value to return when null.

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