![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Generic doubly linked lists. More...
#include <agrum/tools/core/list.h>
Public Member Functions | |
template<typename OtherAlloc > | |
INLINE | List (const List< Val, OtherAlloc > &src) |
template<typename OtherAlloc > | |
INLINE List< Val, Alloc > & | operator= (const List< Val, OtherAlloc > &src) |
template<typename... Args> | |
INLINE ListBucket< Val > * | _createEmplaceBucket_ (Args &&... args) const |
template<typename... Args> | |
INLINE Val & | push_front (Args &&... args) |
template<typename... Args> | |
INLINE Val & | emplaceFront (Args &&... args) |
template<typename... Args> | |
INLINE Val & | push_back (Args &&... args) |
template<typename... Args> | |
INLINE Val & | emplaceBack (Args &&... args) |
template<typename... Args> | |
INLINE Val & | emplace (const const_iterator &iter, Args &&... args) |
template<typename... Args> | |
INLINE Val & | emplace (const const_iterator_safe &iter, Args &&... args) |
template<typename OtherAlloc > | |
INLINE bool | operator== (const List< Val, OtherAlloc > &src) const |
template<typename OtherAlloc > | |
INLINE bool | operator!= (const List< Val, OtherAlloc > &src) const |
Constructors / Destructors | |
List () | |
A basic constructor that creates an empty list. More... | |
List (const List< Val, Alloc > &src) | |
Copy constructor. More... | |
template<typename OtherAlloc > | |
List (const List< Val, OtherAlloc > &src) | |
Ceneralized copy constructor. More... | |
List (List< Val, Alloc > &&src) | |
Move constructor. More... | |
List (std::initializer_list< Val > list) | |
Initializer_list constructor. More... | |
~List () | |
Class destructor. More... | |
Iterators | |
const const_iterator_safe & | cendSafe () const noexcept |
Returns a safe const iterator pointing to the end of the List. More... | |
const iterator_safe & | endSafe () noexcept |
Returns a safe iterator pointing to the end of the List. More... | |
const const_iterator_safe & | crendSafe () const noexcept |
Return a safe const iterator pointing just before the beginning of the List. More... | |
const iterator_safe & | rendSafe () noexcept |
Returns a safe iterator pointing just before the beginning of the List. More... | |
const_iterator_safe | cbeginSafe () const |
Returns a safe const iterator pointing to the beginning of the List. More... | |
iterator_safe | beginSafe () |
Returns a safe iterator pointing to the beginning of the List. More... | |
const_iterator_safe | crbeginSafe () const |
Returns a safe const iterator pointing to the last element of the List. More... | |
iterator_safe | rbeginSafe () |
Returns a safe iterator pointing to the last element of the List. More... | |
const const_iterator & | cend () const noexcept |
Returns an unsafe const iterator pointing to the end of the List. More... | |
const iterator & | end () noexcept |
Returns an unsafe iterator pointing to the end of the List. More... | |
const const_iterator & | end () const noexcept |
Returns an unsafe const iterator pointing to the end of the List. More... | |
const const_iterator & | crend () const noexcept |
Returns an unsafe const iterator pointing just before the beginning of the List. More... | |
const iterator & | rend () noexcept |
Returns an unsafe iterator pointing just before the beginning of the List. More... | |
const const_iterator & | rend () const noexcept |
Returns an unsafe const iterator pointing just before the beginning of the List. More... | |
const_iterator | cbegin () const |
Returns an unsafe const iterator pointing to the beginning of the List. More... | |
iterator | begin () |
Returns an unsafe iterator pointing to the beginning of the List. More... | |
const_iterator | begin () const |
Returns an unsafe const iterator pointing to the beginning of the List. More... | |
const_iterator | crbegin () const |
Returns an unsafe const iterator pointing to the last element of the List. More... | |
iterator | rbegin () |
Returns an unsafe iterator pointing to the last element of the List. More... | |
const_iterator | rbegin () const |
Returns an unsafe const iterator pointing to the last element of the List. More... | |
Accessors / Modifiers | |
Val & | pushFront (const Val &val) |
Inserts a new element (a copy) at the beginning of the chained list. More... | |
Val & | pushFront (Val &&val) |
Inserts a new element (a move) at the beginning of the chained list. More... | |
template<typename... Args> | |
Val & | push_front (Args &&... args) |
An alias for pushFront used for STL compliance. More... | |
template<typename... Args> | |
Val & | emplaceFront (Args &&... args) |
Emplace elements at the beginning of the chained list. More... | |
Val & | pushBack (const Val &val) |
Inserts a new element (a copy) at the end of the chained list. More... | |
Val & | pushBack (Val &&val) |
Inserts a new element (a move) at the end of the chained list. More... | |
template<typename... Args> | |
Val & | push_back (Args &&... args) |
An alias for pushBack used for STL compliance. More... | |
template<typename... Args> | |
Val & | emplaceBack (Args &&... args) |
Emplace elements at the end of the chained list. More... | |
Val & | insert (const Val &val) |
Inserts a new element at the end of the chained list (alias of pushBack). More... | |
Val & | insert (Val &&val) |
Inserts a new element at the end of the chained list (alias of pushBack). More... | |
Val & | insert (Size pos, const Val &val) |
Inserts a new element at the ith pos of the chained list. More... | |
Val & | insert (Size pos, Val &&val) |
Insert an rvalue at the ith pos of the chained list. More... | |
Val & | insert (const const_iterator_safe &iter, const Val &val, location place=location::BEFORE) |
Inserts a new element before or after a given iterator. More... | |
Val & | insert (const const_iterator_safe &iter, Val &&val, location place=location::BEFORE) |
Inserts an rvalue before or after a given iterator. More... | |
Val & | insert (const const_iterator &iter, const Val &val, location place=location::BEFORE) |
Inserts a new element before or after a given iterator. More... | |
Val & | insert (const const_iterator &iter, Val &&val, location place=location::BEFORE) |
Inserts an rvalue before or after a given iterator. More... | |
template<typename... Args> | |
Val & | emplace (const const_iterator &iter, Args &&... args) |
Emplace a new element before a given iterator. More... | |
template<typename... Args> | |
Val & | emplace (const const_iterator_safe &iter, Args &&... args) |
Emplace a new element before a given safe iterator. More... | |
Val & | front () const |
Returns a reference to first element of a list, if any. More... | |
Val & | back () const |
Returns a reference to last element of a list, if any. More... | |
Size | size () const noexcept |
Returns the number of elements in the list. More... | |
bool | exists (const Val &val) const |
Checks whether there exists a given element in the list. More... | |
void | erase (Size i) |
Erases the ith element of the List (the first one is in position 0). More... | |
void | erase (const iterator_safe &iter) |
Erases the element of the List pointed to by the safe iterator. More... | |
void | erase (const const_iterator_safe &iter) |
Erases the element of the List pointed to by the safe const iterator. More... | |
void | eraseByVal (const Val &val) |
erases the first element encountered with a given value. More... | |
void | eraseAllVal (const Val &val) |
erases all the elements encountered with a given value More... | |
void | popBack () |
Removes the last element of a List, if any. More... | |
void | popFront () |
Removes the first element of a List, if any. More... | |
void | clear () |
Deletes all the elements of a chained list. More... | |
bool | empty () const noexcept |
Returns a boolean indicating whether the chained list is empty. More... | |
void | swap (List &other_list) |
Swap the current list with another one. More... | |
std::string | toString () const |
Converts a list into a string. More... | |
template<typename Mount , typename OtherAlloc = std::allocator< Mount >> | |
List< Mount, OtherAlloc > | map (Mount(*f)(Val)) const |
Creates a list of mountains from a list of val. More... | |
template<typename Mount , typename OtherAlloc = std::allocator< Mount >> | |
List< Mount, OtherAlloc > | map (Mount(*f)(Val &)) const |
Creates a list of mountains from a list of val. More... | |
template<typename Mount , typename OtherAlloc = std::allocator< Mount >> | |
List< Mount, OtherAlloc > | map (Mount(*f)(const Val &)) const |
Creates a list of mountains from a list of val. More... | |
template<typename Mount , typename OtherAlloc = std::allocator< Mount >> | |
List< Mount, OtherAlloc > | map (const Mount &mount) const |
Creates a list of mountains with a given value from a list of val. More... | |
Operators | |
List< Val, Alloc > & | operator= (const List< Val, Alloc > &src) |
Copy operator. More... | |
template<typename OtherAlloc > | |
List< Val, Alloc > & | operator= (const List< Val, OtherAlloc > &src) |
Generalized copy operator. More... | |
List< Val, Alloc > & | operator= (List< Val, Alloc > &&src) |
Move operator. More... | |
Val & | operator+= (const Val &val) |
Inserts a new element at the end of the list (alias of pushBack). More... | |
Val & | operator+= (Val &&val) |
Inserts a new element at the end of the list (alias of pushBack). More... | |
template<typename OtherAlloc > | |
bool | operator== (const List< Val, OtherAlloc > &src) const |
Checks whether two lists are identical (same elements in the same order). More... | |
template<typename OtherAlloc > | |
bool | operator!= (const List< Val, OtherAlloc > &src) const |
Checks whether two lists are different (different elements or orders). More... | |
Val & | operator[] (const Size i) |
Returns the ith element in the current chained list. More... | |
const Val & | operator[] (const Size i) const |
Returns the const ith element in the current chained list. More... | |
Public Types | |
enum | location { location::BEFORE, location::AFTER } |
Locations around iterators where insertions of new elements can take / place. More... | |
using | BucketAllocator = typename Alloc::template rebind< ListBucket< Val > >::other |
Type of the allocator for ListBuckets. More... | |
using | value_type = Val |
Types for STL compliance. More... | |
using | reference = Val & |
Types for STL compliance. More... | |
using | const_reference = const Val & |
Types for STL compliance. More... | |
using | pointer = Val * |
Types for STL compliance. More... | |
using | const_pointer = const Val * |
Types for STL compliance. More... | |
using | size_type = Size |
Types for STL compliance. More... | |
using | difference_type = std::ptrdiff_t |
Types for STL compliance. More... | |
using | allocator_type = Alloc |
Types for STL compliance. More... | |
using | iterator = ListIterator< Val > |
Types for STL compliance. More... | |
using | const_iterator = ListConstIterator< Val > |
Types for STL compliance. More... | |
using | iterator_safe = ListIteratorSafe< Val > |
Types for STL compliance. More... | |
using | const_iterator_safe = ListConstIteratorSafe< Val > |
Types for STL compliance. More... | |
Friends | |
class | ListIterator< Val > |
ListIterator should be a friend to optimize access to elements. More... | |
class | ListConstIterator< Val > |
ListIterator should be a friend to optimize access to elements. More... | |
class | ListIteratorSafe< Val > |
ListIterator should be a friend to optimize access to elements. More... | |
class | ListConstIteratorSafe< Val > |
ListIterator should be a friend to optimize access to elements. More... | |
Generic doubly linked lists.
List enables fast and safe manipulation of chained lists. Unless the elements are rvalues, the insertions of new elements into the lists are ALWAYS performed by copy, i.e., each time we add a new element X to the List, a copy of X is actually created and this very copy is stored into the list. For rvalues, move operations are performed.
The List iterators are implemented so as to avoid segmentation faults when elements of the list are deleted while some safe iterators are pointing on them. Moreover they ensure that, when elements are removed from a List, iterators on that list will never access these elements (which is not the case for the iterators in the C++ standard library). Note that this guarantee is ensured at low cost as experimental results show that List and ListIterator are as efficient as their STL counterparts. However, this guarantee can hold only if List is aware of all of the iterators pointing to it: thus, when List erases one element, it can parse the list of its iterators and update those that point toward the now deleted element. When parsing elements without removing any element, you can use unsafe iterators instead of safe ones because they are slightly faster. But those will most certainly segfault if they perform some operations on deleted elements.
using gum::List< Val, Alloc >::allocator_type = Alloc |
using gum::List< Val, Alloc >::BucketAllocator = typename Alloc::template rebind< ListBucket< Val > >::other |
using gum::List< Val, Alloc >::const_iterator = ListConstIterator< Val > |
using gum::List< Val, Alloc >::const_iterator_safe = ListConstIteratorSafe< Val > |
using gum::List< Val, Alloc >::const_pointer = const Val* |
using gum::List< Val, Alloc >::const_reference = const Val& |
using gum::List< Val, Alloc >::difference_type = std::ptrdiff_t |
using gum::List< Val, Alloc >::iterator = ListIterator< Val > |
using gum::List< Val, Alloc >::iterator_safe = ListIteratorSafe< Val > |
using gum::List< Val, Alloc >::value_type = Val |
|
strong |
A basic constructor that creates an empty list.
Definition at line 1141 of file list_tpl.h.
INLINE gum::List< Val, Alloc >::List | ( | const List< Val, Alloc > & | src | ) |
Copy constructor.
The new list and that which is copied do not share their elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. This constructor runs in linear time.
src | the list the contents of which is copied into the current one. |
Definition at line 1151 of file list_tpl.h.
gum::List< Val, Alloc >::List | ( | const List< Val, OtherAlloc > & | src | ) |
Ceneralized copy constructor.
The new list and that which is copied do not share their elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. This constructor runs in linear time.
src | the list the contents of which is copied into the current one. |
OtherAlloc | The other allocator. |
INLINE gum::List< Val, Alloc >::List | ( | List< Val, Alloc > && | src | ) |
Move constructor.
src | The gum::List to move. |
Definition at line 1178 of file list_tpl.h.
INLINE gum::List< Val, Alloc >::List | ( | std::initializer_list< Val > | list | ) |
Initializer_list constructor.
list | The initializer list. |
Definition at line 1194 of file list_tpl.h.
INLINE gum::List< Val, Alloc >::List | ( | const List< Val, OtherAlloc > & | src | ) |
Definition at line 1165 of file list_tpl.h.
|
private |
A function used to perform copies of elements of Lists.
Before performing the copy, we assume in this function that the current list (this) is empty (else there would be memory leak).
OtherAlloc | The other allocator. |
src | The gum::List to copy. |
Definition at line 1071 of file list_tpl.h.
|
private |
Create a new bucket with a given value.
val | The value of the new bucket. |
Definition at line 1419 of file list_tpl.h.
|
private |
Create a new bucket with a given value.
val | The value of the new bucket. |
Definition at line 1435 of file list_tpl.h.
|
private |
Create an emplace bucket.
Args | The emplace arguments types. |
args | The emplace arguments. |
INLINE ListBucket< Val >* gum::List< Val, Alloc >::_createEmplaceBucket_ | ( | Args &&... | args | ) | const |
Definition at line 1452 of file list_tpl.h.
|
private |
Removes an element from a chained list.
If parameter bucket is equal to 0, then the method does not perform anything, else the bucket is deleted. In the latter case, no test is ever performed to check that the bucket does actually belong to the List. The method runs in constant time.
bucket | A pointer on the bucket in the chained list we wish to remove. |
Definition at line 1794 of file list_tpl.h.
|
privatenoexcept |
Returns the bucket corresponding to a given value.
Actually, this is the first bucket of value val encountered in the list, if any, that is returned. If the element cannot be found, 0 is returned. This method enables fast removals of buckets. It runs in linear time.
Comparisons between Val instances are performed through == operators.
val | The value of the element the bucket of which we wish to return. |
Definition at line 1858 of file list_tpl.h.
|
privatenoexcept |
Returns the bucket corresponding to the ith position in the list.
This method assumes that the list contains at least i+1 elements. The index of the first element of the list is 0.
i | The position of the returned element. |
Definition at line 1574 of file list_tpl.h.
|
private |
Inserts a new bucket before or after the location pointed to by an iterator.
iter | An iterator pointing where to insert a new element. |
new_elt | The new element ot insert in the gum::List. |
place | Where to insert the new element relatively to the iterator. |
Definition at line 1647 of file list_tpl.h.
|
private |
Inserts a new bucket before or after the location pointed to by an iterator.
iter | An iterator pointing where to insert a new element. |
new_elt | The new element ot insert in the gum::List. |
place | Where to insert the new element relatively to the iterator. |
Definition at line 1683 of file list_tpl.h.
|
private |
Insert a new bucket after another one.
new_elt | The new element to insert in the gum::List. |
current_elt | The element before which new_elt will be inserted. |
Definition at line 1608 of file list_tpl.h.
|
private |
Insert a new bucket before another one.
new_elt | The new element to insert in the gum::List. |
current_elt | The element before which new_elt will be inserted. |
Definition at line 1588 of file list_tpl.h.
|
private |
Insert a bucket at the end of the list.
new_elt | The new element pushed at the end of the gum::List. |
Definition at line 1489 of file list_tpl.h.
|
private |
Insert a bucket at the front of the list.
new_elt | The new element pushed at the front of the gum::List. |
Definition at line 1470 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::back | ( | ) | const |
Returns a reference to last element of a list, if any.
NotFound | exception is thrown if the list is empty. |
Definition at line 1771 of file list_tpl.h.
INLINE ListIterator< Val > gum::List< Val, Alloc >::begin | ( | ) |
Returns an unsafe iterator pointing to the beginning of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1362 of file list_tpl.h.
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::begin | ( | ) | const |
Returns an unsafe const iterator pointing to the beginning of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Returns an unsafe const iterator pointing to the beginning of the List.
Definition at line 1368 of file list_tpl.h.
INLINE ListIteratorSafe< Val > gum::List< Val, Alloc >::beginSafe | ( | ) |
Returns a safe iterator pointing to the beginning of the List.
Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Definition at line 1350 of file list_tpl.h.
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::cbegin | ( | ) | const |
Returns an unsafe const iterator pointing to the beginning of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1356 of file list_tpl.h.
INLINE ListConstIteratorSafe< Val > gum::List< Val, Alloc >::cbeginSafe | ( | ) | const |
Returns a safe const iterator pointing to the beginning of the List.
Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Definition at line 1344 of file list_tpl.h.
|
noexcept |
Returns an unsafe const iterator pointing to the end of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Returns an unsafe const iterator pointing to the end of the List.
Definition at line 1296 of file list_tpl.h.
|
noexcept |
Returns a safe const iterator pointing to the end of the List.
Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step
Returns a safe const iterator pointing to the end of the List.
Definition at line 1284 of file list_tpl.h.
void gum::List< Val, Alloc >::clear | ( | ) |
Deletes all the elements of a chained list.
All the iterators of the list will be resetted to rend. The method runs in linear time of both the size of the list and the number of iterators attached to the List.
Definition at line 1120 of file list_tpl.h.
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::crbegin | ( | ) | const |
Returns an unsafe const iterator pointing to the last element of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1392 of file list_tpl.h.
INLINE ListConstIteratorSafe< Val > gum::List< Val, Alloc >::crbeginSafe | ( | ) | const |
Returns a safe const iterator pointing to the last element of the List.
Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Definition at line 1374 of file list_tpl.h.
|
noexcept |
Returns an unsafe const iterator pointing just before the beginning of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1326 of file list_tpl.h.
|
noexcept |
Return a safe const iterator pointing just before the beginning of the List.
Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Return a safe const iterator pointing just before the beginning of the List.
Definition at line 1314 of file list_tpl.h.
Val& gum::List< Val, Alloc >::emplace | ( | const const_iterator & | iter, |
Args &&... | args | ||
) |
Emplace a new element before a given iterator.
Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs. The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.
iter | The position in the list |
args | The arguments passed to the constructor |
Val& gum::List< Val, Alloc >::emplace | ( | const const_iterator_safe & | iter, |
Args &&... | args | ||
) |
Emplace a new element before a given safe iterator.
Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs. The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.
iter | The position in the list. |
args | the arguments passed to the constructor. |
INLINE Val& gum::List< Val, Alloc >::emplace | ( | const const_iterator & | iter, |
Args &&... | args | ||
) |
Definition at line 1750 of file list_tpl.h.
INLINE Val& gum::List< Val, Alloc >::emplace | ( | const const_iterator_safe & | iter, |
Args &&... | args | ||
) |
Definition at line 1757 of file list_tpl.h.
Val& gum::List< Val, Alloc >::emplaceBack | ( | Args &&... | args | ) |
Emplace elements at the end of the chained list.
Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs
Args | The emplaced arguments types. |
args | The arguments passed to the constructor |
INLINE Val& gum::List< Val, Alloc >::emplaceBack | ( | Args &&... | args | ) |
Definition at line 1555 of file list_tpl.h.
Val& gum::List< Val, Alloc >::emplaceFront | ( | Args &&... | args | ) |
Emplace elements at the beginning of the chained list.
Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs
args | The arguments passed to the constructor. |
INLINE Val& gum::List< Val, Alloc >::emplaceFront | ( | Args &&... | args | ) |
Definition at line 1529 of file list_tpl.h.
|
noexcept |
Returns a boolean indicating whether the chained list is empty.
Definition at line 1896 of file list_tpl.h.
|
noexcept |
Returns an unsafe iterator pointing to the end of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1302 of file list_tpl.h.
|
noexcept |
Returns an unsafe const iterator pointing to the end of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1308 of file list_tpl.h.
|
noexcept |
Returns a safe iterator pointing to the end of the List.
Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Ceturns a safe iterator pointing to the end of the List.
Definition at line 1290 of file list_tpl.h.
Erases the ith element of the List (the first one is in position 0).
If the element cannot be found, the function returns without throwing any exception. It runs in linear time in the size of the list.
i | The position in the list of the element we wish to remove. |
Definition at line 1837 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::erase | ( | const iterator_safe & | iter | ) |
Erases the element of the List pointed to by the safe iterator.
If the element cannot be found, i.e., it has already been erased or the iterator points to end/rend, the function returns without throwing any exception. It runs in linear time in the size of the list.
iter | An iterator pointing to the element to remove. |
Definition at line 1846 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::erase | ( | const const_iterator_safe & | iter | ) |
Erases the element of the List pointed to by the safe const iterator.
If the element cannot be found, i.e., it has already been erased or the iterator points to end/rend, the function returns without throwing any exception. It runs in linear time in the size of the list.
iter | An iterator pointing to the element to remove. |
Definition at line 1852 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::eraseAllVal | ( | const Val & | val | ) |
erases all the elements encountered with a given value
If no element equal to val can be found, the function returns without throwing any exception.
Comparisons between Val instances are performed through == operators.
val | the value of the element we wish to remove. |
Definition at line 1873 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::eraseByVal | ( | const Val & | val | ) |
erases the first element encountered with a given value.
If no element equal to val can be found, the function returns without throwing any exception. It runs in linear time both in the size of the list and in the number of iterators referenced in the list. Comparisons between Val instances are performed through == operators.
val | The value of the element we wish to remove. |
Definition at line 1867 of file list_tpl.h.
INLINE bool gum::List< Val, Alloc >::exists | ( | const Val & | val | ) | const |
Checks whether there exists a given element in the list.
This method runs in linear time.
Comparisons between Val instances are performed through == operators.
val | the value of the element we wish to check the existence of. |
Definition at line 1785 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::front | ( | ) | const |
Returns a reference to first element of a list, if any.
NotFound | exception is thrown if the list is empty. |
Definition at line 1763 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | const Val & | val | ) |
Inserts a new element at the end of the chained list (alias of pushBack).
val | The value inserted. |
Definition at line 1562 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | Val && | val | ) |
Inserts a new element at the end of the chained list (alias of pushBack).
val | The value inserted. |
Definition at line 1568 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | Size | pos, |
const Val & | val | ||
) |
Inserts a new element at the ith pos of the chained list.
The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.
pos | The position where to inser the new element. |
val | The value to insert. |
Definition at line 1628 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | Size | pos, |
Val && | val | ||
) |
Insert an rvalue at the ith pos of the chained list.
The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.
pos | The position where to inser the new element. |
val | The value to insert. |
Definition at line 1637 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | const const_iterator_safe & | iter, |
const Val & | val, | ||
location | place = location::BEFORE |
||
) |
Inserts a new element before or after a given iterator.
iter | The iterator pointing where to inser the new element. |
val | The value to insert. |
place | Defines where to insert the new element relatively to iter. |
Definition at line 1710 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | const const_iterator_safe & | iter, |
Val && | val, | ||
location | place = location::BEFORE |
||
) |
Inserts an rvalue before or after a given iterator.
iter | The iterator pointing where to inser the new element. |
val | The value to insert. |
place | Defines where to insert the new element relatively to iter. |
Definition at line 1723 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | const const_iterator & | iter, |
const Val & | val, | ||
location | place = location::BEFORE |
||
) |
Inserts a new element before or after a given iterator.
iter | The iterator pointing where to inser the new element. |
val | The value to insert. |
place | Defines where to insert the new element relatively to iter. |
Definition at line 1736 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::insert | ( | const const_iterator & | iter, |
Val && | val, | ||
location | place = location::BEFORE |
||
) |
Inserts an rvalue before or after a given iterator.
iter | The iterator pointing where to inser the new element. |
val | The value to insert. |
place | Defines where to insert the new element relatively to iter. |
Definition at line 1743 of file list_tpl.h.
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map | ( | Mount(*)(Val) | f | ) | const |
Creates a list of mountains from a list of val.
f | A function that maps any Val element into a Mount |
Mount | The type of mountains. |
OtherAlloc | The mountains type allocator. |
Definition at line 1921 of file list_tpl.h.
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map | ( | Mount(*)(Val &) | f | ) | const |
Creates a list of mountains from a list of val.
f | A function that maps any Val element into a Mount |
Mount | The type of mountains. |
OtherAlloc | The mountains type allocator. |
Definition at line 1936 of file list_tpl.h.
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map | ( | Mount(*)(const Val &) | f | ) | const |
Creates a list of mountains from a list of val.
f | A function that maps any Val element into a Mount |
Mount | The type of mountains. |
OtherAlloc | The mountains type allocator. |
Definition at line 1951 of file list_tpl.h.
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map | ( | const Mount & | mount | ) | const |
Creates a list of mountains with a given value from a list of val.
mount | the value taken by all the elements of the resulting list |
Mount | The type of mountains. |
OtherAlloc | The mountains type allocator. |
Definition at line 1966 of file list_tpl.h.
bool gum::List< Val, Alloc >::operator!= | ( | const List< Val, OtherAlloc > & | src | ) | const |
Checks whether two lists are different (different elements or orders).
This method runs in time linear in the number of elements of the list.
OtherAlloc | The other allocator. |
INLINE bool gum::List< Val, Alloc >::operator!= | ( | const List< Val, OtherAlloc > & | src | ) | const |
Definition at line 2009 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::operator+= | ( | const Val & | val | ) |
Inserts a new element at the end of the list (alias of pushBack).
This enables writing code like list
+=
xxx
; to add element xxx
to the list.
val | Tha value inserted int the list. |
Definition at line 1980 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::operator+= | ( | Val && | val | ) |
Inserts a new element at the end of the list (alias of pushBack).
This enables writing code like list
+=
xxx
; to add element xxx
to the list.
val | Tha value inserted int the list. |
Definition at line 1987 of file list_tpl.h.
INLINE List< Val, Alloc > & gum::List< Val, Alloc >::operator= | ( | const List< Val, Alloc > & | src | ) |
Copy operator.
The new list and that which is copied do not share the elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. The List on which the operator is applied keeps its iterator's list. Of course, if it previously contained some elements, those are removed prior to the copy. This operator runs in linear time.
src | the list the content of which will be copied into the current List. |
Definition at line 1220 of file list_tpl.h.
List< Val, Alloc >& gum::List< Val, Alloc >::operator= | ( | const List< Val, OtherAlloc > & | src | ) |
Generalized copy operator.
The new list and that which is copied do not share the elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. The List on which the operator is applied keeps its iterator's list. Of course, if it previously contained some elements, those are removed prior to the copy. This operator runs in linear time.
src | the list the content of which will be copied into the current List. |
INLINE List< Val, Alloc > & gum::List< Val, Alloc >::operator= | ( | List< Val, Alloc > && | src | ) |
Move operator.
src | The gum::List to move. |
Definition at line 1257 of file list_tpl.h.
INLINE List< Val, Alloc >& gum::List< Val, Alloc >::operator= | ( | const List< Val, OtherAlloc > & | src | ) |
Definition at line 1239 of file list_tpl.h.
bool gum::List< Val, Alloc >::operator== | ( | const List< Val, OtherAlloc > & | src | ) | const |
Checks whether two lists are identical (same elements in the same order).
This method runs in time linear in the number of elements of the list.
OtherAlloc | The other allocator. |
INLINE bool gum::List< Val, Alloc >::operator== | ( | const List< Val, OtherAlloc > & | src | ) | const |
Definition at line 1994 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::operator[] | ( | const Size | i | ) |
Returns the ith element in the current chained list.
The first of the list element has index 0.
This method runs in linear time.
i | The position of the element in the list (0 = first element). |
NotFound | Raised if the element to be retrieved does not exist. |
Definition at line 2015 of file list_tpl.h.
INLINE const Val & gum::List< Val, Alloc >::operator[] | ( | const Size | i | ) | const |
Returns the const ith element in the current chained list.
The first of the list element has index 0.
This method runs in linear time.
i | the position of the element in the list (0 = first element). |
NotFound | Raised if the element to be retrieved does not exist. |
Definition at line 2024 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::popBack | ( | ) |
Removes the last element of a List, if any.
When the list is empty, it does not do anything.
Definition at line 1884 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::popFront | ( | ) |
Removes the first element of a List, if any.
When the list is empty, it does not do anything.
Definition at line 1890 of file list_tpl.h.
Val& gum::List< Val, Alloc >::push_back | ( | Args &&... | args | ) |
An alias for pushBack used for STL compliance.
Defining push_back allows using, for instance, BackInserters.
Args | The emplace arguments type. |
args | The emplace arguments values. |
INLINE Val& gum::List< Val, Alloc >::push_back | ( | Args &&... | args | ) |
Definition at line 1548 of file list_tpl.h.
Val& gum::List< Val, Alloc >::push_front | ( | Args &&... | args | ) |
An alias for pushFront used for STL compliance.
Defining push_front allows using, for instance, FrontInserters.
Args | The emplace values type. |
args | The emplace values. |
INLINE Val& gum::List< Val, Alloc >::push_front | ( | Args &&... | args | ) |
Definition at line 1522 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::pushBack | ( | const Val & | val | ) |
Inserts a new element (a copy) at the end of the chained list.
The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.
val | The value pushed back. |
Definition at line 1535 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::pushBack | ( | Val && | val | ) |
Inserts a new element (a move) at the end of the chained list.
The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.
val | The value pushed back. |
Definition at line 1541 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::pushFront | ( | const Val & | val | ) |
Inserts a new element (a copy) at the beginning of the chained list.
The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.
val | The valus pushed at the front. |
Definition at line 1509 of file list_tpl.h.
INLINE Val & gum::List< Val, Alloc >::pushFront | ( | Val && | val | ) |
Inserts a new element (a move) at the beginning of the chained list.
val | The valus pushed at the front. |
Definition at line 1515 of file list_tpl.h.
INLINE ListIterator< Val > gum::List< Val, Alloc >::rbegin | ( | ) |
Returns an unsafe iterator pointing to the last element of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1401 of file list_tpl.h.
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::rbegin | ( | ) | const |
Returns an unsafe const iterator pointing to the last element of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1410 of file list_tpl.h.
INLINE ListIteratorSafe< Val > gum::List< Val, Alloc >::rbeginSafe | ( | ) |
Returns a safe iterator pointing to the last element of the List.
Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Definition at line 1383 of file list_tpl.h.
|
noexcept |
Returns an unsafe iterator pointing just before the beginning of the List.
Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Returns an unsafe iterator pointing just before the beginning of the List.
Definition at line 1332 of file list_tpl.h.
|
noexcept |
Returns an unsafe const iterator pointing just before the beginning of the List.
Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.
Definition at line 1338 of file list_tpl.h.
|
noexcept |
Returns a safe iterator pointing just before the beginning of the List.
Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.
Definition at line 1320 of file list_tpl.h.
|
noexcept |
Returns the number of elements in the list.
This method runs in constant time.
Definition at line 1779 of file list_tpl.h.
INLINE void gum::List< Val, Alloc >::swap | ( | List< Val, Alloc > & | other_list | ) |
Swap the current list with another one.
other_list | The list to swap elements with. |
Definition at line 2033 of file list_tpl.h.
std::string gum::List< Val, Alloc >::toString | ( | ) | const |
Converts a list into a string.
Definition at line 1902 of file list_tpl.h.
|
friend |
ListIterator should be a friend to optimize access to elements.
|
friend |
ListIterator should be a friend to optimize access to elements.
|
friend |
ListIterator should be a friend to optimize access to elements.
|
friend |
ListIterator should be a friend to optimize access to elements.
|
mutableprivate |
|
private |
|
private |
|
mutableprivate |