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 (hxnil_t) noexcept
constexpr hxptr (hxptr &&x_) noexcept
constexpr ~hxptr (void) noexcept
constexpr hxptr & operator= (hxptr &&x_) noexcept
constexpr T & operator* (void) const
constexpr T * operator-> (void) const
constexpr operator bool (void) const
constexpr bool operator== (const hxptr &x_) const
constexpr bool operator== (hxnil_t) const
template<typename self_t_, typename callable_t_>
constexpr auto and_then (this self_t_ &&self_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxdeclval< T & >()))>
constexpr const deleter_t_ & deleter (void) const
constexpr deleter_t_ & deleter (void)
template<hxsystem_allocator_t allocator_ = hxsystem_allocator_current, hxalignment_t alignment_ = hxalignment, typename... args_t_>
T & emplace (args_t_ &&... args_) noexcept
constexpr bool equal (const hxptr &x_) const
constexpr T * get (void) const
hxhash_t hash (void) const
constexpr bool has_value (void) const
template<typename self_t_, typename callable_t_>
requires (hxis_rvalue_reference<self_t_&&>() && !hxis_const<hxremove_reference_t<self_t_>>())
constexpr hxptr or_else (this self_t_ &&self_, callable_t_ &&callable_)
constexpr T * release (void)
constexpr void reset (T *ptr_=0) noexcept
constexpr void swap (hxptr &x_) noexcept
constexpr T & value (void) const
template<typename self_t_, typename... args_t_>
constexpr hxremove_cv_t< T > value_or (this self_t_ &&self_, args_t_ &&... args_)

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/3]

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/3]

template<typename T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ >::hxptr ( hxnil_t )
inlineconstexprnoexcept

Constructs a null hxptr from hxnil.

  • hxnil : The error sentinel.

◆ hxptr() [3/3]

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

Move constructor.

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

  • x : 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 self_t_, typename callable_t_>
auto hxptr< T, deleter_t_ >::and_then ( this self_t_ && self_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxdeclval< T & >()))>
constexpr

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

Use and_then to return hxptr, hxref or hxexpected.

  • 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

◆ 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.

◆ emplace()

template<typename T, typename deleter_t_ = hxdefault_delete>
template<hxsystem_allocator_t allocator_ = hxsystem_allocator_current, hxalignment_t alignment_ = hxalignment, typename... args_t_>
T & hxptr< T, deleter_t_ >::emplace ( args_t_ &&... args_)
noexcept

Replaces the owned object with one constructed from args and returns a reference to it.

  • args : Arguments forwarded to the object constructor.

◆ equal()

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

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

  • x : The hxptr to compare against.

◆ 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.

◆ has_value()

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

Returns true if the owned pointer is non-null.

◆ hash()

template<typename T, typename deleter_t_ = hxdefault_delete>
hxhash_t hxptr< T, deleter_t_ >::hash ( void ) const

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

◆ operator bool()

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

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_ > && x_)
constexprnoexcept

Move assignment.

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

  • x : 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_ > & x_) const
inlineconstexpr

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

  • x : The hxptr to compare against.

◆ operator==() [2/2]

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

Returns true if the owned pointer is null.

◆ or_else()

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename self_t_, typename callable_t_>
requires (hxis_rvalue_reference<self_t_&&>() && !hxis_const<hxremove_reference_t<self_t_>>())
hxptr hxptr< T, deleter_t_ >::or_else ( this self_t_ && self_,
callable_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.

◆ 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_ > & x_)
constexprnoexcept

Exchanges ownership with x.

Neither pointer is deleted.

  • x : The hxptr to swap with.

◆ value()

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

Returns a reference to the owned object without releasing ownership.

◆ value_or()

template<typename T, typename deleter_t_ = hxdefault_delete>
template<typename self_t_, typename... args_t_>
hxremove_cv_t< T > hxptr< T, deleter_t_ >::value_or ( this self_t_ && self_,
args_t_ &&... args_ )
constexpr

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