44# ifndef TPL_DYNDLIST_H
45# define TPL_DYNDLIST_H
115 template <
typename T =
int>
174 return p->get_data();
181 return p->get_data();
287 return this->
get_next()->get_data();
293 return this->
get_prev()->get_data();
300 <<
"DynDlist is empty";
308 <<
"DynDlist is empty";
348 <<
"DynDlist is empty";
360 <<
"DynDlist is empty";
443 const auto count_nodes = [] (
const DynDlist & list)
noexcept ->
size_t
446 for (
auto it = list.get_it(); it.has_curr(); it.next_ne())
451 l.num_elem = count_nodes(
l);
452 r.num_elem = count_nodes(r);
470 <<
"lists are not empty";
589 <<
"DynDlist Iterator has not current";
608 <<
"DynDlist Iterator has not current";
627 <<
"DynDlist Iterator has not current";
646 <<
"DynDlist Iterator has not current";
671 <<
"DynDlist Iterator has not current";
698 <<
"DynDlist Iterator has not current";
716 <<
"DynDlist Iterator has not current";
800 for (
size_t i = 0; i < n && it.has_curr(); ++i)
804 <<
"DynDlist index out of range";
806 return it.get_curr();
824 for (
auto it = this->
get_it(); it.has_curr(); it.next_ne())
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
STL-compatible iterator adapters for Aleph containers.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Functional programming utilities for Aleph-w containers.
Iterator traits and STL-compatible iterator wrappers.
void put_itor_at_the_end(Itor &it) noexcept
void next_ne() noexcept
Move the iterator one position backward guaranteeing no exception.
bool has_curr() const noexcept
Return true if the iterator has current item.
void next()
Move the iterator one position forward.
void prev()
Move the iterator one position backward.
void reset_last() noexcept
Reset the iterator to the last item of list.
void reset_first() noexcept
Reset the iterator to the first item of list.
void insert_list(Dlink *head) noexcept
Insert the list head before this
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
void append(Dlink *node) noexcept
Insert node before this.
size_t reverse() noexcept
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
size_t split_list(Dlink &l, Dlink &r) noexcept
void append_list(Dlink *head) noexcept
Insert the list head after this
void insert(Dlink *node) noexcept
Insert node after this.
Iterator on a list of Dnode objects.
Dnode< T > * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Dnode< T > * get_curr() const
Return a pointer to the current node.
Node belonging to a double circular linked list with header node.
Dnode< T > *& get_next() const noexcept
Return the next node to this
Dnode< T > * remove_next() noexcept
Remove the next node to this; return its address.
T & get_data() noexcept
Return a modifiable reference to the data contained in the node.
Dnode< T > *& get_prev() const noexcept
Return the previous node to this
static Dnode * data_to_node(T &data) noexcept
Given an reference to the data in the node, returns a pointer to the Dnode object that contains it.
Dnode< T > * remove_prev() noexcept
Remove the previous node to this; return its address.
void append_list(DynDlist &list)
Move and append all elements of list before the current item of iterator.
T Item_Type
The type of element stored in the container.
typename Dnode< T >::Iterator Base
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
void insert(const T &item)
Insert by copy an item after the current item.
T & get_curr() const
Return the current item; throw overflow_error if there is no current item.
void reset_last() noexcept
Reset the iterator to the last item.
Iterator & operator=(const Iterator &it) noexcept
void end() noexcept
Put the iterator at the end state (where there is no current item)
void prev()
Move the iterator one item backward.
long get_pos() const noexcept
Return the ordinal position of current item.
void insert(T &&item)
Insert by movement an item after the current item.
T del()
Remove from the list the current node and move the iterator one position forward.
void append(T &&item)
Append by movement an item after the current item.
void insert_list(DynDlist &list)
Move and insert all elements of list after the current item of iterator.
void reset_first() noexcept
Reset the iterator to the first item.
Iterator(const DynDlist< T > &list) noexcept
Initialize the iterator to the first item of list
void append(const T &item)
Append by copy an item before the current item.
void next()
Move the iterator one item forward.
T & get_curr_ne() const noexcept
Dynamic doubly linked list with O(1) size and bidirectional access.
T & get_last() const
Return a modifiable reference to last item in the list.
void insert(DynDlist &&list) noexcept
const size_t & size() const noexcept
Return the number of elements (constant time)
DynDlist & reverse() noexcept
T Key_Type
The type of element that stores the container.
T & __insert(Dnode< T > *p) noexcept
T & front()
If this was treated as a queue, the it returns the most oldlest inserted item.
DynDlist< T > reverse() const
Return a reversed copy of this
T & get_first_ne() const noexcept
Return a modifiable reference to first item in the list.
T & operator[](const size_t n) const
Return a modifiable reference to the i-th item of the list.
void split_list(DynDlist &l, DynDlist &r)
Split the list in two.
void swap(DynDlist &l) noexcept
Swap in constant time all the items of this with all the items of l (very fast!)
T Item_Type
The type of element that stores the container.
T remove_last()
Remove the last item of the list; return a copy of removed item.
DynDlist(DynDlist< T > &&list) noexcept
Move constructor; all items of list are moved.
void remove(T &data) noexcept
Assuming that data is a reference to the item in the list, it removes the item.
void insert(const DynDlist &list)
Insert all the elements of list before this.
void empty() noexcept
Empty the list.
T & append(const T &item)
Append a copied item at the end of the list.
void __append(DynDlist< T > &list) noexcept
T & append(T &&item)
Append a moved item at the end of the list.
DynDlist & rev() noexcept
T & rear()
If this was treated as a queue, the it returns the most recently inserted item.
void split(DynDlist &l, DynDlist &r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynDlist< T > rev() const
T & get_first() const
Return a modifiable reference to first item in the list.
void erase(T &data) noexcept
void __insert(DynDlist< T > &list) noexcept
T & get_last_ne() const noexcept
Return a modifiable reference to last item in the list.
T & __append(Dnode< T > *p) noexcept
void append(DynDlist &&list) noexcept
T & insert(const T &item)
Insert a copy of item at the beginning of the list.
void append(const DynDlist &list)
Append all the elements of list after this.
T remove_first_ne() noexcept
Remove the first item of the list; return a copy of removed item.
T remove_last_ne() noexcept
Remove the last item of the list; return a copy of removed item.
DynDlist< T > & operator=(const DynDlist &list)
Assignment by copy.
T remove_first()
Remove the first item of the list; return a copy of removed item.
T & insert(T &&item)
Insert a moved item at the beginning of the list.
void split_list_ne(DynDlist &l, DynDlist &r) noexcept
Split the list in two.
DynDlist(const DynDlist &list)
Copy constructor; all items of list are copied.
constexpr bool is_empty() const noexcept
Return true if list is empty.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Generic list of items stored in a container.
Generic traversal of the container through its iterator.
Special constructors common to Aleph-w ( ) containers.
Doubly linked list node with typed data.