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

#include <hxlist.hpp>

Classes

class  const_iterator
class  iterator

Public Types

using T = T

Public Member Functions

 hxlist (deleter_t_ deleter_=deleter_t_())
 ~hxlist (void)
bool operator== (const hxlist &x_) const
bool operator< (const hxlist &x_) const
template<hxrange_concept_ range_t_, hxenable_if_t<!hxis_lvalue_reference< range_t_ >(), int > = 0>
void add_range (range_t_ &&range_) noexcept
const T & back (void) const
T & back (void)
const_iterator begin (void) const
iterator begin (void)
const_iterator cbegin (void) const
const_iterator cend (void) const
template<typename deleter_u_>
void clear (deleter_u_ &&deleter_) noexcept
void clear (void)
bool empty (void) const
const_iterator end (void) const
iterator end (void)
template<typename deleter_u_>
void erase (const_iterator it_, deleter_u_ &&deleter_) noexcept
void erase (const_iterator it_) noexcept
hxptr< T, deleter_t_ > extract (const_iterator it_)
template<typename callable_t_>
const_iterator find_if (callable_t_ &&callable_) const
template<typename callable_t_>
iterator find_if (callable_t_ &&callable_)
template<typename callable_t_>
void for_each (callable_t_ &&callable_) const
template<typename callable_t_>
void for_each (callable_t_ &&callable_)
const deleter_t_ & deleter (void) const
deleter_t_ & deleter (void)
const T & front (void) const
T & front (void)
template<typename deleter_u_>
iterator insert_after (const_iterator it_, hxptr< T, deleter_u_ > &&ptr_)
iterator insert_after (const_iterator it_, T *ptr_)
template<typename deleter_u_>
iterator insert (const_iterator it_, hxptr< T, deleter_u_ > &&ptr_)
iterator insert (const_iterator it_, T *ptr_)
hxptr< T, deleter_t_ > pop_back (void)
hxptr< T, deleter_t_ > pop_front (void)
template<typename deleter_u_>
iterator push_back (hxptr< T, deleter_u_ > &&ptr_)
iterator push_back (T *ptr_)
template<typename deleter_u_>
iterator push_front (hxptr< T, deleter_u_ > &&ptr_)
iterator push_front (T *ptr_)
void release_all (void)
template<typename callable_t_, typename deleter_u_>
hxsize_t remove_if (callable_t_ &&callable_, deleter_u_ &&deleter_) noexcept
template<typename callable_t_>
hxsize_t remove_if (callable_t_ &&callable_) noexcept
void reverse (void)
hxsize_t size (void) const
void splice (const_iterator it_, hxlist &x_)

Detailed Description

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
class hxlist< T, deleter_t_ >

hxlist - An intrusive doubly linked list that takes ownership of nodes via a deleter_t callable, defaulting to hxdefault_delete.

This is the same as hxconstexpr_list except that it does not work with constexpr as it uses pointer arithmetic to save one pointer per-node. T must derive from hxlist_node. The destructor calls clear() which invokes the deleter on all remaining nodes. Subclasses of T may be inserted heterogeneously. Use hxdo_not_delete to avoid freeing nodes. Note: It is possible to iterate backwards from --list.end() to --list.begin() however reverse iterators are not provided.

For example:

struct example_t : public hxlist_node {
example_t(int x) : value(x) { }
int value;
};
for(example_t& n : list) {
::printf("%d\n", n.value);
}
hxlist_node - Intrusive doubly linked list node base.
Definition hxlist.hpp:43
iterator push_back(hxptr< T, deleter_u_ > &&ptr_)
push_back - Inserts the node owned by ptr at the back of the list.
hxlist(deleter_t_ deleter_=deleter_t_())
Constructs an empty list with an optional deleter instance.
T * hxnew(Args_ &&... args_) noexcept
hxnew<T, allocator, align>(...) - Allocates and constructs an object of type T using an optional memo...
Definition hxmemory_manager.h:245
  • T : The node type. Must derive from hxlist_node.
  • deleter_t : A class type invoked as deleter(T*) to free the owned pointer. See also hxdo_not_delete.

Member Typedef Documentation

◆ T

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
using hxlist< T, deleter_t_ >::T = T

Constructor & Destructor Documentation

◆ hxlist()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxlist< T, deleter_t_ >::hxlist ( deleter_t_ deleter_ = deleter_t_())
explicit

Constructs an empty list with an optional deleter instance.

  • deleter : Callable with signature bool deleter(T*).

◆ ~hxlist()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxlist< T, deleter_t_ >::~hxlist ( void )
inline

Destroys the list by calling clear(), which invokes the deleter on every remaining node.

Member Function Documentation

◆ add_range()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<hxrange_concept_ range_t_, hxenable_if_t<!hxis_lvalue_reference< range_t_ >(), int > = 0>
void hxlist< T, deleter_t_ >::add_range ( range_t_ && range_)
noexcept

Links each T from a temporary range into this list by address, exactly as push_back(T*) would.

The range's nodes are threaded into the list in place and are not copied or allocated, so range must own storage it is relinquishing to the list.

  • range : The range of nodes to link into the list.

◆ back() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
T & hxlist< T, deleter_t_ >::back ( void )

◆ back() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const T & hxlist< T, deleter_t_ >::back ( void ) const

Returns a const reference to the last node. The list must not be empty.

◆ begin() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::begin ( void )

◆ begin() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const_iterator hxlist< T, deleter_t_ >::begin ( void ) const

Returns a const iterator to the first node, or end() if the list is empty.

◆ cbegin()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const_iterator hxlist< T, deleter_t_ >::cbegin ( void ) const
inline

Returns a const iterator to the first node, or cend() if the list is empty.

◆ cend()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const_iterator hxlist< T, deleter_t_ >::cend ( void ) const
inline

Returns a const iterator to the sentinel, representing one past the last node.

◆ clear() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
void hxlist< T, deleter_t_ >::clear ( deleter_u_ && deleter_)
noexcept

Removes all nodes, invoking deleter on each.

If deleter evaluates to false nodes are unlinked but not freed.

  • deleter : Callable with signature bool deleter(T*).

◆ clear() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::clear ( void )
inline

Removes all nodes using the stored deleter.

◆ deleter() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
deleter_t_ & hxlist< T, deleter_t_ >::deleter ( void )

◆ deleter() [2/2]

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

Returns a const reference to the stored deleter.

◆ empty()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
bool hxlist< T, deleter_t_ >::empty ( void ) const
inline

Returns true if the list contains no nodes.

◆ end() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::end ( void )

◆ end() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const_iterator hxlist< T, deleter_t_ >::end ( void ) const

Returns a const iterator to the sentinel, representing one past the last node.

This is also the iterator to one before the first node.

◆ erase() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::erase ( const_iterator it_)
noexcept

Unlinks and deletes the node at it using the stored deleter.

  • it : Iterator to the node to unlink and delete.

◆ erase() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
void hxlist< T, deleter_t_ >::erase ( const_iterator it_,
deleter_u_ && deleter_ )
noexcept

Unlinks the node at it and invokes deleter on it.

If deleter evaluates to false it is not called.

  • it : The node to unlink and erase.
  • deleter : Callable with signature bool deleter(T*).

◆ extract()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ > hxlist< T, deleter_t_ >::extract ( const_iterator it_)

extract - Returns an hxptr owning the node at it after unlinking it from the list.

  • it : Iterator to the node to unlink and return.

◆ find_if() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_>
iterator hxlist< T, deleter_t_ >::find_if ( callable_t_ && callable_)

Non-const version of find_if.

◆ find_if() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_>
const_iterator hxlist< T, deleter_t_ >::find_if ( callable_t_ && callable_) const

Finds the first node for which the predicate returns true.

Returns end() if no node matches.

  • callable : A callable taking a T reference, returning bool.

◆ for_each() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_>
void hxlist< T, deleter_t_ >::for_each ( callable_t_ && callable_)

Non-const version of for_each.

◆ for_each() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_>
void hxlist< T, deleter_t_ >::for_each ( callable_t_ && callable_) const

Calls a function, lambda, or std::function on each node.

  • callable : A callable taking a T reference.

◆ front() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
T & hxlist< T, deleter_t_ >::front ( void )

◆ front() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
const T & hxlist< T, deleter_t_ >::front ( void ) const

Returns a const reference to the first node. The list must not be empty.

◆ insert() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
iterator hxlist< T, deleter_t_ >::insert ( const_iterator it_,
hxptr< T, deleter_u_ > && ptr_ )

insert - Inserts the node owned by ptr immediately before it.

Returns an iterator to the inserted node.

  • it : Iterator to the node before which ptr is inserted. May be end().
  • ptr : The hxptr owning the node to insert.

◆ insert() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::insert ( const_iterator it_,
T * ptr_ )

insert - Inserts ptr immediately before it.

May be end(). Returns an iterator to the inserted node.

  • it : Iterator to the node before which ptr is inserted.
  • ptr : The node to insert. Must not be null.

◆ insert_after() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
iterator hxlist< T, deleter_t_ >::insert_after ( const_iterator it_,
hxptr< T, deleter_u_ > && ptr_ )

insert_after - Inserts the node owned by ptr immediately after it.

Returns an iterator to the inserted node.

  • it : Iterator to the node after which ptr is inserted.
  • ptr : The hxptr owning the node to insert.

◆ insert_after() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::insert_after ( const_iterator it_,
T * ptr_ )

insert_after - Inserts ptr immediately after it.

Returns an iterator to the inserted node.

  • it : Iterator to the node after which ptr is inserted.
  • ptr : The node to insert. Must not be null.

◆ operator<()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
bool hxlist< T, deleter_t_ >::operator< ( const hxlist< T, deleter_t_ > & x_) const

Returns true if this list compares less than x lexicographically, using T's operator== and operator<.

  • x : The list to compare against.

◆ operator==()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
bool hxlist< T, deleter_t_ >::operator== ( const hxlist< T, deleter_t_ > & x_) const

Returns true if this list and x contain the same nodes in the same order, using T's operator==.

  • x : The list to compare against.

◆ pop_back()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ > hxlist< T, deleter_t_ >::pop_back ( void )

pop_back - Returns an hxptr owning the last node.

The list must not be empty.

◆ pop_front()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxptr< T, deleter_t_ > hxlist< T, deleter_t_ >::pop_front ( void )

pop_front - Returns an hxptr owning the first node.

The list must not be empty.

◆ push_back() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
iterator hxlist< T, deleter_t_ >::push_back ( hxptr< T, deleter_u_ > && ptr_)

push_back - Inserts the node owned by ptr at the back of the list.

Returns an iterator to the inserted node.

  • ptr : The hxptr owning the node to append. Must not be null.

◆ push_back() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::push_back ( T * ptr_)

push_back - Inserts ptr at the back of the list.

Must not be null. Returns an iterator to the inserted node.

  • ptr : The node to append.

◆ push_front() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
iterator hxlist< T, deleter_t_ >::push_front ( hxptr< T, deleter_u_ > && ptr_)

push_front - Inserts the node owned by ptr at the front of the list.

Returns an iterator to the inserted node.

  • ptr : The hxptr owning the node to prepend. Must not be null.

◆ push_front() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::push_front ( T * ptr_)

push_front - Inserts ptr at the front of the list.

Must not be null. Returns an iterator to the inserted node.

  • ptr : The node to prepend.

◆ release_all()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::release_all ( void )

Resets the list to empty without invoking the deleter on any node.

Ownership of all nodes is abandoned. Use only when nodes are managed elsewhere or have already been freed.

◆ remove_if() [1/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_>
hxsize_t hxlist< T, deleter_t_ >::remove_if ( callable_t_ && callable_)
noexcept

Removes all nodes for which predicate returns true, invoking the stored deleter on each removed node.

Returns the number of nodes removed.

  • callable : A callable taking a T reference, returning bool.

◆ remove_if() [2/2]

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
template<typename callable_t_, typename deleter_u_>
hxsize_t hxlist< T, deleter_t_ >::remove_if ( callable_t_ && callable_,
deleter_u_ && deleter_ )
noexcept

Removes all nodes for which predicate returns true, invoking deleter on each removed node.

If deleter evaluates to false nodes are unlinked but not freed. Returns the number of nodes removed.

  • callable : A callable taking a T reference, returning bool.
  • deleter : Callable with signature bool deleter(T*).

◆ reverse()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::reverse ( void )

Reverses the order of nodes in the list in-place.

WARNING: Iterators are invalidated.

◆ size()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
hxsize_t hxlist< T, deleter_t_ >::size ( void ) const
inline

Returns the number of nodes currently in the list.

◆ splice()

template<hxlist_concept_ T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::splice ( const_iterator it_,
hxlist< T, deleter_t_ > & x_ )

Transfers all nodes from x and inserts them before it, taking ownership.

x is left empty after the call.

  • it : Iterator before which nodes are inserted.
  • x : The list to splice from. Left empty after the call.

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