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)
Tback (void)
const Tback (void) const
iterator begin (void)
const_iterator begin (void) const
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
iterator end (void)
const_iterator end (void) const
template<typename deleter_u_>
void erase (const_iterator pos_, deleter_u_ &&deleter_) noexcept
void erase (const_iterator pos_) noexcept
hxptr< T, deleter_t_ > extract (const_iterator pos_)
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)
Tfront (void)
const Tfront (void) const
template<typename deleter_u_>
iterator insert_after (const_iterator pos_, hxptr< T, deleter_u_ > &&ptr_)
iterator insert_after (const_iterator pos_, T *ptr_)
template<typename deleter_u_>
iterator insert (const_iterator pos_, hxptr< T, deleter_u_ > &&ptr_)
iterator insert (const_iterator pos_, 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 pos_, hxlist &other_)

Detailed Description

template<typename 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:28
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:235
  • 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<typename T, typename deleter_t_ = hxdefault_delete>
using hxlist< T, deleter_t_ >::T = T

Constructor & Destructor Documentation

◆ hxlist()

template<typename 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<typename 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

◆ back() [1/2]

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

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

◆ back() [2/2]

template<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::begin ( void )

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

◆ begin() [2/2]

template<typename 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<typename 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<typename 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<typename 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<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
deleter_t_ & hxlist< T, deleter_t_ >::deleter ( void )

Returns a reference to the stored deleter.

◆ deleter() [2/2]

template<typename 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<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
iterator hxlist< T, deleter_t_ >::end ( void )

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

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

◆ end() [2/2]

template<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::erase ( const_iterator pos_)
noexcept

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

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

◆ erase() [2/2]

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

Unlinks the node at pos and invokes deleter on it.

If deleter evaluates to false it is not called.

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

◆ extract()

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

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

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

◆ find_if() [1/2]

template<typename 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<typename 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<typename 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<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
T & hxlist< T, deleter_t_ >::front ( void )

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

◆ front() [2/2]

template<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
template<typename deleter_u_>
iterator hxlist< T, deleter_t_ >::insert ( const_iterator pos_,
hxptr< T, deleter_u_ > && ptr_ )

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

Returns an iterator to the inserted node.

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

◆ insert() [2/2]

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

insert - Inserts ptr immediately before pos.

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

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

◆ insert_after() [1/2]

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

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

Returns an iterator to the inserted node.

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

◆ insert_after() [2/2]

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

insert_after - Inserts ptr immediately after pos.

Returns an iterator to the inserted node.

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

◆ pop_back()

template<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename T, typename deleter_t_ = hxdefault_delete>
void hxlist< T, deleter_t_ >::splice ( const_iterator pos_,
hxlist< T, deleter_t_ > & other_ )

Transfers all nodes from other and inserts them before pos, taking ownership.

other is left empty after the call.

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

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