aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::List< Val, Alloc > Class Template Reference

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_safecendSafe () const noexcept
 Returns a safe const iterator pointing to the end of the List. More...
 
const iterator_safeendSafe () noexcept
 Returns a safe iterator pointing to the end of the List. More...
 
const const_iterator_safecrendSafe () const noexcept
 Return a safe const iterator pointing just before the beginning of the List. More...
 
const iterator_saferendSafe () 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_iteratorcend () const noexcept
 Returns an unsafe const iterator pointing to the end of the List. More...
 
const iteratorend () noexcept
 Returns an unsafe iterator pointing to the end of the List. More...
 
const const_iteratorend () const noexcept
 Returns an unsafe const iterator pointing to the end of the List. More...
 
const const_iteratorcrend () const noexcept
 Returns an unsafe const iterator pointing just before the beginning of the List. More...
 
const iteratorrend () noexcept
 Returns an unsafe iterator pointing just before the beginning of the List. More...
 
const const_iteratorrend () 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...
 

Detailed Description

template<typename Val, typename Alloc = std::allocator< Val >>
class gum::List< Val, Alloc >

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.

Usage example:
// creation of an empty list
List<int> list1;
List<int> list2 { 3, 4, 5 }; // initializer list
// adding elements to the list
list1.pushFront (23);
list1.pushBack (10);
list1 += 25;
list1.insert (12);
// getting the second element of the list
cerr << "10 = " << list1[1] << endl;
// getting the first and last elements
cerr << "first = " << list1.front() << " last = " << list1.back() << endl;
// get the number of elements in the list
cerr << "number of elements = " << list1.size () << endl;
// display the content of the list
cerr << list1 << endl;
// copy the list
List<int> list2 = list1, list3;
list3 = list1;
// delete the second element from the list
list1.erase (1);
// delete the first and last elements
list1.popFront ();
list1.popBack ();
// delete element whose value is 25
list1.eraseByVal (25);
// check whether the list is empty
if (list1.empty()) cerr << "empty list" << endl;
// remove all elements from the list
list1.clear ();
// parse all the elements of a list using unsafe iterators
for (List<int>::iterator iter = list2.begin();
iter != list2.end(); ++iter)
cerr << *iter << endl;
for (List<int>::iterator iter = list2.rbegin();
iter != list2.rend(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.cbegin();
iter != list2.cend(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.crbegin();
iter != list2.crend(); --iter)
cerr << *iter << endl;
// parse all the elements of a list using safe iterators
for (List<int>::iterator_safe iter = list2.beginSafe();
iter != list2.endSafe(); ++iter)
cerr << *iter << endl;
for (List<int>::iterator_safe iter = list2.rbeginSafe();
iter != list2.rendSafe(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.cbeginSafe();
iter != list2.cendSafe(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.crbeginSafe();
iter != list2.crendSafe(); --iter)
cerr << *iter << endl;
// use an iterator to point the element we wish to erase
List<int>::iterator_safe iter = list2.beginSafe();
List2.erase ( iter );
List<int>::iterator iter2 = list2.begin() + 4; // 5th element of the list
iter2 = iter + 4;
// map a list into another list (assuming function f is defined as
// float f (int x) { return (2.5 * x); } )
List<float> flist = list2.map (f);
Template Parameters
ValThe values type stored in the gum::List.
AllocThe allocator for the values stored in the gum::List.

Definition at line 372 of file list.h.

Member Typedef Documentation

◆ allocator_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::allocator_type = Alloc

Types for STL compliance.

Definition at line 383 of file list.h.

◆ BucketAllocator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::BucketAllocator = typename Alloc::template rebind< ListBucket< Val > >::other

Type of the allocator for ListBuckets.

Definition at line 391 of file list.h.

◆ const_iterator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_iterator = ListConstIterator< Val >

Types for STL compliance.

Definition at line 385 of file list.h.

◆ const_iterator_safe

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_iterator_safe = ListConstIteratorSafe< Val >

Types for STL compliance.

Definition at line 387 of file list.h.

◆ const_pointer

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_pointer = const Val*

Types for STL compliance.

Definition at line 380 of file list.h.

◆ const_reference

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_reference = const Val&

Types for STL compliance.

Definition at line 378 of file list.h.

◆ difference_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 382 of file list.h.

◆ iterator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::iterator = ListIterator< Val >

Types for STL compliance.

Definition at line 384 of file list.h.

◆ iterator_safe

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::iterator_safe = ListIteratorSafe< Val >

Types for STL compliance.

Definition at line 386 of file list.h.

◆ pointer

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::pointer = Val*

Types for STL compliance.

Definition at line 379 of file list.h.

◆ reference

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::reference = Val&

Types for STL compliance.

Definition at line 377 of file list.h.

◆ size_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::size_type = Size

Types for STL compliance.

Definition at line 381 of file list.h.

◆ value_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::value_type = Val

Types for STL compliance.

Definition at line 376 of file list.h.

Member Enumeration Documentation

◆ location

template<typename Val, typename Alloc = std::allocator< Val >>
enum gum::List::location
strong

Locations around iterators where insertions of new elements can take / place.

Enumerator
BEFORE 
AFTER 

Definition at line 395 of file list.h.

396  {
397  BEFORE,
398  AFTER
399  };

Constructor & Destructor Documentation

◆ List() [1/6]

template<typename Val , typename Alloc >
INLINE gum::List< Val, Alloc >::List ( )

A basic constructor that creates an empty list.

Definition at line 1141 of file list_tpl.h.

1141  {
1142  // for debugging purposes
1143  GUM_CONSTRUCTOR(List);
1144 
1145  // reserve space for only the default number of iterators
1147  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:41
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141

◆ List() [2/6]

template<typename Val, typename Alloc>
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.

Parameters
srcthe list the contents of which is copied into the current one.

Definition at line 1151 of file list_tpl.h.

1151  {
1152  // for debugging purposes
1153  GUM_CONS_CPY(List);
1154 
1155  // copy the elements
1156  _copy_elements_(src);
1157 
1158  // reserve space for only the default number of iterators
1160  }
void _copy_elements_(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1071
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:41
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141

◆ List() [3/6]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
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.

Parameters
srcthe list the contents of which is copied into the current one.
Template Parameters
OtherAllocThe other allocator.

◆ List() [4/6]

template<typename Val, typename Alloc>
INLINE gum::List< Val, Alloc >::List ( List< Val, Alloc > &&  src)

Move constructor.

Parameters
srcThe gum::List to move.

Definition at line 1178 of file list_tpl.h.

1178  :
1179  _deb_list_{std::move(src._deb_list_)}, _end_list_{std::move(src._end_list_)},
1180  _nb_elements_{std::move(src._nb_elements_)},
1181  _safe_iterators_{std::move(src._safe_iterators_)}, _alloc_bucket_{
1182  std::move(src._alloc_bucket_)} {
1183  // for debugging purposes
1184  GUM_CONS_MOV(List);
1185 
1186  src._deb_list_ = nullptr;
1187  src._end_list_ = nullptr;
1188  src._nb_elements_ = 0;
1189  src._safe_iterators_.clear();
1190  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ List() [5/6]

template<typename Val, typename Alloc>
INLINE gum::List< Val, Alloc >::List ( std::initializer_list< Val >  list)

Initializer_list constructor.

Parameters
listThe initializer list.

Definition at line 1194 of file list_tpl.h.

1194  {
1195  // for debugging purposes
1196  GUM_CONSTRUCTOR(List);
1197 
1198  // adding all the elements
1199  for (const auto& val: list) {
1200  pushBack(val);
1201  }
1202 
1203  // reserve space for only the default number of iterators
1205  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:41
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141

◆ ~List()

template<typename Val , typename Alloc >
INLINE gum::List< Val, Alloc >::~List ( )

Class destructor.

Definition at line 1209 of file list_tpl.h.

1209  {
1210  // for debugging (although this program is bug-free)
1211  GUM_DESTRUCTOR(List);
1212 
1213  // we detach all the safe iterators attached to the current List and we
1214  // remove all the elements from the list
1215  clear();
1216  }
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1120

◆ List() [6/6]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE gum::List< Val, Alloc >::List ( const List< Val, OtherAlloc > &  src)

Definition at line 1165 of file list_tpl.h.

1165  {
1166  // for debugging purposes
1167  GUM_CONS_CPY(List);
1168 
1169  // copy the elements
1170  _copy_elements_(src);
1171 
1172  // reserve space for only the default number of iterators
1174  }
void _copy_elements_(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1071
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:41
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141

Member Function Documentation

◆ _copy_elements_()

template<typename Val, typename Alloc >
template<typename OtherAlloc >
void gum::List< Val, Alloc >::_copy_elements_ ( const List< Val, OtherAlloc > &  src)
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).

Template Parameters
OtherAllocThe other allocator.
Parameters
srcThe gum::List to copy.

Definition at line 1071 of file list_tpl.h.

1071  {
1072  ListBucket< Val >* ptr;
1073  ListBucket< Val >* old_ptr = nullptr;
1074  ListBucket< Val >* new_elt = nullptr;
1075 
1076  // copy src's list
1077  try {
1078  for (ptr = src._deb_list_; ptr != nullptr; ptr = ptr->_next_) {
1079  // create a copy bucket
1080  new_elt = _alloc_bucket_.allocate(1);
1081 
1082  try {
1083  _alloc_bucket_.construct(new_elt, *ptr);
1084  } catch (...) {
1085  _alloc_bucket_.deallocate(new_elt, 1);
1086  throw;
1087  }
1088 
1089  // rechain properly the new list (the next field is already initialized
1090  // with nullptr)
1091  new_elt->_prev_ = old_ptr;
1092 
1093  if (old_ptr)
1094  old_ptr->_next_ = new_elt;
1095  else
1096  _deb_list_ = new_elt;
1097 
1098  old_ptr = new_elt;
1099  }
1100  } catch (...) {
1101  // problem: we could not allocate an element in the list => we delete
1102  // the elements created so far and we throw an exception
1103  for (; _deb_list_ != nullptr; _deb_list_ = const_cast< ListBucket< Val >* >(ptr)) {
1104  ptr = _deb_list_->_next_;
1105  _alloc_bucket_.destroy(_deb_list_);
1106  _alloc_bucket_.deallocate(_deb_list_, 1);
1107  }
1108 
1109  _deb_list_ = nullptr;
1110  throw;
1111  }
1112 
1113  // update properly the end of the chained list and the number of elements
1114  _end_list_ = old_ptr;
1115  _nb_elements_ = src._nb_elements_;
1116  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ _createBucket_() [1/2]

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::_createBucket_ ( const Val &  val) const
private

Create a new bucket with a given value.

Parameters
valThe value of the new bucket.
Returns
Returns the bucket holding val.

Definition at line 1419 of file list_tpl.h.

1419  {
1420  // create a new bucket (catch allocation and construction exceptions)
1421  ListBucket< Val >* new_elt = _alloc_bucket_.allocate(1);
1422 
1423  try {
1424  _alloc_bucket_.construct(new_elt, val);
1425  } catch (...) {
1426  _alloc_bucket_.deallocate(new_elt, 1);
1427  throw;
1428  }
1429 
1430  return new_elt;
1431  }
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ _createBucket_() [2/2]

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::_createBucket_ ( Val &&  val) const
private

Create a new bucket with a given value.

Parameters
valThe value of the new bucket.
Returns
Returns the bucket holding val.

Definition at line 1435 of file list_tpl.h.

1435  {
1436  // create a new bucket (catch allocation and construction exceptions)
1437  ListBucket< Val >* new_elt = _alloc_bucket_.allocate(1);
1438 
1439  try {
1440  _alloc_bucket_.construct(new_elt, std::move(val));
1441  } catch (...) {
1442  _alloc_bucket_.deallocate(new_elt, 1);
1443  throw;
1444  }
1445 
1446  return new_elt;
1447  }
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ _createEmplaceBucket_() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
ListBucket< Val >* gum::List< Val, Alloc >::_createEmplaceBucket_ ( Args &&...  args) const
private

Create an emplace bucket.

Template Parameters
ArgsThe emplace arguments types.
Parameters
argsThe emplace arguments.
Returns
Returns the bucket holding the new value.

◆ _createEmplaceBucket_() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE ListBucket< Val >* gum::List< Val, Alloc >::_createEmplaceBucket_ ( Args &&...  args) const

Definition at line 1452 of file list_tpl.h.

1452  {
1453  // create a new bucket (catch allocation and construction exceptions)
1454  ListBucket< Val >* new_elt = _alloc_bucket_.allocate(1);
1455 
1456  try {
1457  _alloc_bucket_.construct(new_elt,
1459  std::forward< Args >(args)...);
1460  } catch (...) {
1461  _alloc_bucket_.deallocate(new_elt, 1);
1462  throw;
1463  }
1464 
1465  return new_elt;
1466  }
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ _erase_()

template<typename Val, typename Alloc >
INLINE void gum::List< Val, Alloc >::_erase_ ( ListBucket< Val > *  bucket)
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.

Parameters
bucketA pointer on the bucket in the chained list we wish to remove.

Definition at line 1794 of file list_tpl.h.

1794  {
1795  // perform deletion only if there is a bucket to remove
1796  if (bucket != nullptr) {
1797  // update the iterators pointing on this element
1798  for (const auto ptr_iter: _safe_iterators_) {
1799  if (ptr_iter->_bucket_ == bucket) {
1800  ptr_iter->_next_current_bucket_ = bucket->_prev_;
1801  ptr_iter->_prev_current_bucket_ = bucket->_next_;
1802  ptr_iter->_bucket_ = nullptr;
1803  ptr_iter->_null_pointing_ = true;
1804  } else {
1805  if (ptr_iter->_null_pointing_) {
1806  if (ptr_iter->_next_current_bucket_ == bucket)
1807  ptr_iter->_next_current_bucket_ = bucket->_prev_;
1808 
1809  if (ptr_iter->_prev_current_bucket_ == bucket)
1810  ptr_iter->_prev_current_bucket_ = bucket->_next_;
1811  }
1812  }
1813  }
1814 
1815  // set properly the begin and end of the chained list (the other chainings
1816  // will be performed by operator delete)
1817  if (bucket->_prev_ == nullptr)
1818  _deb_list_ = bucket->_next_;
1819  else
1820  bucket->_prev_->_next_ = bucket->_next_;
1821 
1822  if (bucket->_next_ == nullptr)
1823  _end_list_ = bucket->_prev_;
1824  else
1825  bucket->_next_->_prev_ = bucket->_prev_;
1826 
1827  // remove the current element src the list
1828  _alloc_bucket_.destroy(bucket);
1829  _alloc_bucket_.deallocate(bucket, 1);
1830 
1831  --_nb_elements_;
1832  }
1833  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ _getBucket_()

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::_getBucket_ ( const Val &  val) const
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.

Parameters
valThe value of the element the bucket of which we wish to return.
Returns
Returns the bucket corresponding to a given value.

Definition at line 1858 of file list_tpl.h.

1858  {
1859  for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1860  if (ptr->_val_ == val) return ptr;
1861 
1862  return nullptr;
1863  }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ _getIthBucket_()

template<typename Val , typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::_getIthBucket_ ( Size  i) const
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.

Parameters
iThe position of the returned element.
Returns
Returns the gum::ListBucket of the ith element.

Definition at line 1574 of file list_tpl.h.

1574  {
1575  ListBucket< Val >* ptr;
1576 
1577  if (i < _nb_elements_ / 2) {
1578  for (ptr = _deb_list_; i; --i, ptr = ptr->_next_) {}
1579  } else {
1580  for (ptr = _end_list_, i = _nb_elements_ - i - 1; i; --i, ptr = ptr->_prev_) {}
1581  }
1582 
1583  return ptr;
1584  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ _insert_() [1/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_insert_ ( const const_iterator_safe iter,
ListBucket< Val > *  new_elt,
location  place 
)
private

Inserts a new bucket before or after the location pointed to by an iterator.

Parameters
iterAn iterator pointing where to insert a new element.
new_eltThe new element ot insert in the gum::List.
placeWhere to insert the new element relatively to the iterator.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1647 of file list_tpl.h.

1649  {
1650  // find the location around which the new element should be inserted
1651  ListBucket< Val >* ptr;
1652 
1653  if (iter._null_pointing_) {
1654  if (place == location::BEFORE) {
1655  ptr = iter._next_current_bucket_;
1656  } else {
1657  ptr = iter._prev_current_bucket_;
1658  }
1659  } else {
1660  ptr = iter._getBucket_();
1661  }
1662 
1663  if (ptr == nullptr) {
1664  // here, we are at the end of the list
1665  return _pushBack_(new_elt);
1666  } else {
1667  switch (place) {
1668  case location::BEFORE:
1669  return _insertBefore_(new_elt, ptr);
1670 
1671  case location::AFTER:
1672  return _insertAfter_(new_elt, ptr);
1673 
1674  default:
1675  GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1676  }
1677  }
1678  }
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1588
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1489
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1608
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ _insert_() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_insert_ ( const const_iterator iter,
ListBucket< Val > *  new_elt,
location  place 
)
private

Inserts a new bucket before or after the location pointed to by an iterator.

Parameters
iterAn iterator pointing where to insert a new element.
new_eltThe new element ot insert in the gum::List.
placeWhere to insert the new element relatively to the iterator.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1683 of file list_tpl.h.

1685  {
1686  // find the location around which the new element should be inserted
1687  ListBucket< Val >* ptr = iter._getBucket_();
1688 
1689  if (ptr == nullptr) {
1690  // here, we are at the end of the list
1691  return _pushBack_(new_elt);
1692  } else {
1693  switch (place) {
1694  case location::BEFORE:
1695  return _insertBefore_(new_elt, ptr);
1696 
1697  case location::AFTER:
1698  return _insertAfter_(new_elt, ptr);
1699 
1700  default:
1701  GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1702  }
1703  }
1704  }
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1588
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1489
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1608
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ _insertAfter_()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_insertAfter_ ( ListBucket< Val > *  new_elt,
ListBucket< Val > *  current_elt 
)
private

Insert a new bucket after another one.

Parameters
new_eltThe new element to insert in the gum::List.
current_eltThe element before which new_elt will be inserted.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1608 of file list_tpl.h.

1609  {
1610  new_elt->_prev_ = current_elt;
1611  new_elt->_next_ = current_elt->_next_;
1612  current_elt->_next_ = new_elt;
1613 
1614  if (new_elt->_next_ == nullptr)
1615  _end_list_ = new_elt;
1616  else
1617  new_elt->_next_->_prev_ = new_elt;
1618 
1619  // update the number of elements
1620  ++_nb_elements_;
1621 
1622  // returns the current value
1623  return new_elt->_val_;
1624  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303

◆ _insertBefore_()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_insertBefore_ ( ListBucket< Val > *  new_elt,
ListBucket< Val > *  current_elt 
)
private

Insert a new bucket before another one.

Parameters
new_eltThe new element to insert in the gum::List.
current_eltThe element before which new_elt will be inserted.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1588 of file list_tpl.h.

1589  {
1590  new_elt->_next_ = current_elt;
1591  new_elt->_prev_ = current_elt->_prev_;
1592  current_elt->_prev_ = new_elt;
1593 
1594  if (new_elt->_prev_ == nullptr)
1595  _deb_list_ = new_elt;
1596  else
1597  new_elt->_prev_->_next_ = new_elt;
1598 
1599  // update the number of elements
1600  ++_nb_elements_;
1601 
1602  // returns the current value
1603  return new_elt->_val_;
1604  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ _pushBack_()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_pushBack_ ( ListBucket< Val > *  new_elt)
private

Insert a bucket at the end of the list.

Parameters
new_eltThe new element pushed at the end of the gum::List.
Returns
Returns a refefence over the value stored in the gum::List.

Definition at line 1489 of file list_tpl.h.

1489  {
1490  // place the bucket at the end of the list
1491  new_elt->_prev_ = _end_list_;
1492 
1493  if (_end_list_ != nullptr)
1494  _end_list_->_next_ = new_elt;
1495  else
1496  _deb_list_ = new_elt;
1497 
1498  _end_list_ = new_elt;
1499 
1500  // update the number of elements
1501  ++_nb_elements_;
1502 
1503  // returns the current value
1504  return new_elt->_val_;
1505  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ _pushFront_()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::_pushFront_ ( ListBucket< Val > *  new_elt)
private

Insert a bucket at the front of the list.

Parameters
new_eltThe new element pushed at the front of the gum::List.
Returns
Returns a refefence over the value stored in the gum::List.

Definition at line 1470 of file list_tpl.h.

1470  {
1471  new_elt->_next_ = _deb_list_;
1472 
1473  if (_deb_list_ != nullptr)
1474  _deb_list_->_prev_ = new_elt;
1475  else
1476  _end_list_ = new_elt;
1477 
1478  _deb_list_ = new_elt;
1479 
1480  // update the number of elements
1481  ++_nb_elements_;
1482 
1483  // return the inserted element
1484  return new_elt->_val_;
1485  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ back()

template<typename Val , typename Alloc >
INLINE Val & gum::List< Val, Alloc >::back ( ) const

Returns a reference to last element of a list, if any.

Exceptions
NotFoundexception is thrown if the list is empty.

Definition at line 1771 of file list_tpl.h.

1771  {
1772  if (_nb_elements_ == Size(0)) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1773 
1774  return _end_list_->_val_;
1775  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ begin() [1/2]

template<typename Val , typename Alloc >
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.

Returns
Returns an unsafe iterator pointing to the beginning of the List.

Definition at line 1362 of file list_tpl.h.

1362  {
1363  return ListIterator< Val >{*this};
1364  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1437

◆ begin() [2/2]

template<typename Val , typename Alloc >
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.

1368  {
1369  return ListConstIterator< Val >{*this};
1370  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ beginSafe()

template<typename Val , typename Alloc >
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.

Returns
Returns a safe iterator pointing to the beginning of the List.

Definition at line 1350 of file list_tpl.h.

1350  {
1351  return ListIteratorSafe< Val >{*this};
1352  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1439

◆ cbegin()

template<typename Val , typename Alloc >
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.

Returns
Returns an unsafe const iterator pointing to the beginning of the List.

Definition at line 1356 of file list_tpl.h.

1356  {
1357  return ListConstIterator< Val >{*this};
1358  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ cbeginSafe()

template<typename Val , typename Alloc >
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.

Returns
Returns a safe const iterator pointing to the beginning of the List.

Definition at line 1344 of file list_tpl.h.

1344  {
1345  return ListConstIteratorSafe< Val >{*this};
1346  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1440

◆ cend()

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::cend ( ) const
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.

1296  {
1297  return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1298  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ cendSafe()

template<typename Val , typename Alloc >
INLINE const ListConstIteratorSafe< Val > & gum::List< Val, Alloc >::cendSafe ( ) const
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.

1284  {
1285  return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1286  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1440

◆ clear()

template<typename Val , typename Alloc >
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.

1120  {
1121  // first we update all the safe iterators of the list : they should now
1122  // point to end/rend
1123  for (const auto ptr_iter: _safe_iterators_) {
1124  ptr_iter->clear();
1125  }
1126 
1127  // clear all the values
1128  for (ListBucket< Val >*ptr = _deb_list_, *next_ptr = nullptr; ptr != nullptr; ptr = next_ptr) {
1129  next_ptr = ptr->_next_;
1130  _alloc_bucket_.destroy(ptr);
1131  _alloc_bucket_.deallocate(ptr, 1);
1132  }
1133 
1134  _nb_elements_ = 0;
1135  _deb_list_ = nullptr;
1136  _end_list_ = nullptr;
1137  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ crbegin()

template<typename Val , typename Alloc >
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.

Returns
Returns an unsafe const iterator pointing to the last element of the List.

Definition at line 1392 of file list_tpl.h.

1392  {
1393  if (_nb_elements_)
1394  return ListConstIterator< Val >{*this, _nb_elements_ - 1};
1395  else
1396  return ListConstIterator< Val >{};
1397  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ crbeginSafe()

template<typename Val , typename Alloc >
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.

Returns
Returns a safe const iterator pointing to the last element of the List.

Definition at line 1374 of file list_tpl.h.

1374  {
1375  if (_nb_elements_)
1376  return ListConstIteratorSafe< Val >{*this, _nb_elements_ - 1};
1377  else
1379  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1440
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303

◆ crend()

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::crend ( ) const
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.

Returns
Returns an unsafe const iterator pointing just before the beginning of the List

Definition at line 1326 of file list_tpl.h.

1326  {
1327  return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1328  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ crendSafe()

template<typename Val , typename Alloc >
INLINE const ListConstIteratorSafe< Val > & gum::List< Val, Alloc >::crendSafe ( ) const
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.

1314  {
1315  return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1316  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1440

◆ emplace() [1/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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.

Parameters
iterThe position in the list
argsThe arguments passed to the constructor
Returns
Returns a reference on the copy inserted into the list.

◆ emplace() [2/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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.

Parameters
iterThe position in the list.
argsthe arguments passed to the constructor.
Returns
Returns a reference on the copy inserted into the list.

◆ emplace() [3/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplace ( const const_iterator iter,
Args &&...  args 
)

Definition at line 1750 of file list_tpl.h.

1750  {
1751  return _insert_(iter, _createEmplaceBucket_(std::forward< Args >(args)...), location::BEFORE);
1752  }
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.

◆ emplace() [4/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplace ( const const_iterator_safe iter,
Args &&...  args 
)

Definition at line 1757 of file list_tpl.h.

1757  {
1758  return _insert_(iter, _createEmplaceBucket_(std::forward< Args >(args)...), location::BEFORE);
1759  }
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.

◆ emplaceBack() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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

Template Parameters
ArgsThe emplaced arguments types.
Parameters
argsThe arguments passed to the constructor
Returns
A reference on the copy inserted into the list.

◆ emplaceBack() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplaceBack ( Args &&...  args)

Definition at line 1555 of file list_tpl.h.

1555  {
1556  return _pushBack_(_createEmplaceBucket_(std::forward< Args >(args)...));
1557  }
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1489
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.

◆ emplaceFront() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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

Parameters
argsThe arguments passed to the constructor.
Returns
Returns a reference on the copy inserted into the list.

◆ emplaceFront() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplaceFront ( Args &&...  args)

Definition at line 1529 of file list_tpl.h.

1529  {
1530  return _pushFront_(_createEmplaceBucket_(std::forward< Args >(args)...));
1531  }
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1470
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.

◆ empty()

template<typename Val , typename Alloc >
INLINE bool gum::List< Val, Alloc >::empty ( ) const
noexcept

Returns a boolean indicating whether the chained list is empty.

Returns
Returns a boolean indicating whether the chained list is empty.

Definition at line 1896 of file list_tpl.h.

1896  {
1897  return (_nb_elements_ == Size(0));
1898  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ end() [1/2]

template<typename Val , typename Alloc >
INLINE const ListIterator< Val > & gum::List< Val, Alloc >::end ( )
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.

Returns
Returns an unsafe iterator pointing to the end of the List.

Definition at line 1302 of file list_tpl.h.

1302  {
1303  return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1304  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1437

◆ end() [2/2]

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::end ( ) const
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
Returns an unsafe const iterator pointing to the end of the List.

Definition at line 1308 of file list_tpl.h.

1308  {
1309  return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1310  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ endSafe()

template<typename Val , typename Alloc >
INLINE const ListIteratorSafe< Val > & gum::List< Val, Alloc >::endSafe ( )
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.

1290  {
1291  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1292  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1439

◆ erase() [1/3]

template<typename Val , typename Alloc >
INLINE void gum::List< Val, Alloc >::erase ( Size  i)

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.

Parameters
iThe position in the list of the element we wish to remove.

Definition at line 1837 of file list_tpl.h.

1837  {
1838  if (i >= _nb_elements_) return;
1839 
1840  // erase the ith bucket
1841  _erase_(_getIthBucket_(i));
1842  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1574

◆ erase() [2/3]

template<typename Val , typename Alloc >
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.

Parameters
iterAn iterator pointing to the element to remove.

Definition at line 1846 of file list_tpl.h.

1846  {
1847  _erase_(iter._getBucket_());
1848  }
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ erase() [3/3]

template<typename Val , typename Alloc >
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.

Parameters
iterAn iterator pointing to the element to remove.

Definition at line 1852 of file list_tpl.h.

1852  {
1853  _erase_(iter._getBucket_());
1854  }
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ eraseAllVal()

template<typename Val, typename Alloc >
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.

Parameters
valthe value of the element we wish to remove.

Definition at line 1873 of file list_tpl.h.

1873  {
1874  for (ListBucket< Val >*iter = _deb_list_, *next_bucket = nullptr; iter != nullptr;
1875  iter = next_bucket) {
1876  next_bucket = iter->_next_;
1877 
1878  if (val == iter->_val_) _erase_(iter);
1879  }
1880  }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ eraseByVal()

template<typename Val, typename Alloc >
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.

Parameters
valThe value of the element we wish to remove.

Definition at line 1867 of file list_tpl.h.

1867  {
1868  _erase_(_getBucket_(val));
1869  }
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition: list_tpl.h:1858
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ exists()

template<typename Val, typename Alloc >
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.

Parameters
valthe value of the element we wish to check the existence of.
Returns
Returns true if val is in the gum::List.

Definition at line 1785 of file list_tpl.h.

1785  {
1786  for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1787  if (ptr->_val_ == val) return true;
1788 
1789  return false;
1790  }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ front()

template<typename Val , typename Alloc >
INLINE Val & gum::List< Val, Alloc >::front ( ) const

Returns a reference to first element of a list, if any.

Exceptions
NotFoundexception is thrown if the list is empty.

Definition at line 1763 of file list_tpl.h.

1763  {
1764  if (_nb_elements_ == Size(0)) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1765 
1766  return _deb_list_->_val_;
1767  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ insert() [1/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::insert ( const Val &  val)

Inserts a new element at the end of the chained list (alias of pushBack).

Parameters
valThe value inserted.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1562 of file list_tpl.h.

1562  {
1563  return pushBack(val);
1564  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535

◆ insert() [2/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::insert ( Val &&  val)

Inserts a new element at the end of the chained list (alias of pushBack).

Parameters
valThe value inserted.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1568 of file list_tpl.h.

1568  {
1569  return pushBack(std::move(val));
1570  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535

◆ insert() [3/8]

template<typename Val, typename Alloc >
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.

Parameters
posThe position where to inser the new element.
valThe value to insert.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1628 of file list_tpl.h.

1628  {
1629  // if ther are fewer elements than pos, put the value at the end of the list
1630  if (_nb_elements_ <= pos) { return pushBack(val); }
1631 
1632  return _insertBefore_(_createBucket_(val), _getIthBucket_(pos));
1633  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1588
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1574

◆ insert() [4/8]

template<typename Val, typename Alloc >
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.

Parameters
posThe position where to inser the new element.
valThe value to insert.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1637 of file list_tpl.h.

1637  {
1638  // if ther are fewer elements than pos, put the value at the end of the list
1639  if (_nb_elements_ <= pos) { return pushBack(std::move(val)); }
1640 
1641  return _insertBefore_(_createBucket_(std::move(val)), _getIthBucket_(pos));
1642  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1588
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1574

◆ insert() [5/8]

template<typename Val, typename Alloc >
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.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1710 of file list_tpl.h.

1710  {
1711  // if the iterator does not point to the list, raise an exception
1712  if (iter._list_ != this) {
1713  GUM_ERROR(InvalidArgument, "the iterator does not point to the correct list")
1714  }
1715 
1716  return _insert_(iter, _createBucket_(val), place);
1717  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ insert() [6/8]

template<typename Val, typename Alloc >
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.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1723 of file list_tpl.h.

1723  {
1724  // if the iterator does not point to the list, raise an exception
1725  if (iter._list_ != this) {
1726  GUM_ERROR(InvalidArgument, "the iterator does not point to the correct list")
1727  }
1728 
1729  return _insert_(iter, _createBucket_(std::move(val)), place);
1730  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ insert() [7/8]

template<typename Val, typename Alloc >
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.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1736 of file list_tpl.h.

1736  {
1737  return _insert_(iter, _createBucket_(val), place);
1738  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647

◆ insert() [8/8]

template<typename Val, typename Alloc >
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.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1743 of file list_tpl.h.

1743  {
1744  return _insert_(iter, _createBucket_(std::move(val)), place);
1745  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1647

◆ map() [1/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(Val)  f) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.
OtherAllocThe mountains type allocator.

Definition at line 1921 of file list_tpl.h.

1921  {
1922  // create a new empty list
1923  List< Mount, OtherAlloc > list;
1924 
1925  // fill the new list
1926  for (const_iterator iter = begin(); iter != end(); ++iter) {
1927  list.pushBack(f(*iter));
1928  }
1929 
1930  return list;
1931  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1302
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1362

◆ map() [2/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(Val &)  f) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.
OtherAllocThe mountains type allocator.

Definition at line 1936 of file list_tpl.h.

1936  {
1937  // create a new empty list
1938  List< Mount, OtherAlloc > list;
1939 
1940  // fill the new list
1941  for (const_iterator iter = begin(); iter != end(); ++iter) {
1942  list.pushBack(f(*iter));
1943  }
1944 
1945  return list;
1946  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1302
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1362

◆ map() [3/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(const Val &)  f) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.
OtherAllocThe mountains type allocator.

Definition at line 1951 of file list_tpl.h.

1951  {
1952  // create a new empty list
1953  List< Mount, OtherAlloc > list;
1954 
1955  // fill the new list
1956  for (const_iterator iter = begin(); iter != end(); ++iter) {
1957  list.pushBack(f(*iter));
1958  }
1959 
1960  return list;
1961  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1302
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1362

◆ map() [4/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
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.

Parameters
mountthe value taken by all the elements of the resulting list
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.
OtherAllocThe mountains type allocator.

Definition at line 1966 of file list_tpl.h.

1966  {
1967  // create a new empty list
1968  List< Mount, OtherAlloc > list;
1969 
1970  // fill the new list
1971  for (Size i = Size(0); i < _nb_elements_; ++i)
1972  list.pushBack(mount);
1973 
1974  return list;
1975  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ operator!=() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
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.

Returns
Returns true if src and this gum::List are identical.
Template Parameters
OtherAllocThe other allocator.

◆ operator!=() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE bool gum::List< Val, Alloc >::operator!= ( const List< Val, OtherAlloc > &  src) const

Definition at line 2009 of file list_tpl.h.

2009  {
2010  return !operator==(src);
2011  }
bool operator==(const List< Val, OtherAlloc > &src) const
Checks whether two lists are identical (same elements in the same order).

◆ operator+=() [1/2]

template<typename Val, typename Alloc >
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.

Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.
Parameters
valTha value inserted int the list.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1980 of file list_tpl.h.

1980  {
1981  return pushBack(val);
1982  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535

◆ operator+=() [2/2]

template<typename Val, typename Alloc >
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.

Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.
Parameters
valTha value inserted int the list.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1987 of file list_tpl.h.

1987  {
1988  return pushBack(std::move(val));
1989  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535

◆ operator=() [1/4]

template<typename Val, typename Alloc>
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.

Warning
If the current List previously contained iterators, those will be resetted to end()/rend().
Parameters
srcthe list the content of which will be copied into the current List.
Returns
Returns this gum::List.

Definition at line 1220 of file list_tpl.h.

1220  {
1221  // avoid self assignment
1222  if (this != &src) {
1223  // for debugging purposes
1224  GUM_OP_CPY(List);
1225 
1226  // remove the old content of 'this' and update accordingly the iterators
1227  clear();
1228 
1229  // perform the copy
1230  _copy_elements_(src);
1231  }
1232 
1233  return *this;
1234  }
void _copy_elements_(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1071
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1120

◆ operator=() [2/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
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.

Warning
If the current List previously contained iterators, those will be resetted to end()/rend().
Parameters
srcthe list the content of which will be copied into the current List.
Returns
Returns this gum::List.

◆ operator=() [3/4]

template<typename Val, typename Alloc>
INLINE List< Val, Alloc > & gum::List< Val, Alloc >::operator= ( List< Val, Alloc > &&  src)

Move operator.

Parameters
srcThe gum::List to move.
Returns
Returns this gum::List.

Definition at line 1257 of file list_tpl.h.

1257  {
1258  // avoid self assignment
1259  if (this != &src) {
1260  // for debugging purposes
1261  GUM_OP_MOV(List);
1262 
1263  // remove the old content of 'this' and update accordingly the iterators
1264  clear();
1265 
1266  // perform the move
1267  _deb_list_ = std::move(src._deb_list_);
1268  _end_list_ = std::move(src._end_list_);
1269  _nb_elements_ = std::move(src._nb_elements_);
1270  _safe_iterators_ = std::move(src._safe_iterators_);
1271  _alloc_bucket_ = std::move(src._alloc_bucket_);
1272 
1273  src._deb_list_ = nullptr;
1274  src._end_list_ = nullptr;
1275  src._nb_elements_ = 0;
1276  src._safe_iterators_.clear();
1277  }
1278 
1279  return *this;
1280  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1120
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ operator=() [4/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE List< Val, Alloc >& gum::List< Val, Alloc >::operator= ( const List< Val, OtherAlloc > &  src)

Definition at line 1239 of file list_tpl.h.

1239  {
1240  // avoid self assignment
1241  if (this != reinterpret_cast< List< Val, Alloc >* >(&src)) {
1242  // for debugging purposes
1243  GUM_OP_CPY(List);
1244 
1245  // remove the old content of 'this' and update accordingly the iterators
1246  clear();
1247 
1248  // perform the copy
1249  _copy_elements_(src);
1250  }
1251 
1252  return *this;
1253  }
void _copy_elements_(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1071
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1141
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1120

◆ operator==() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
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.

Returns
Returns true if src and this gum::List are identical.
Template Parameters
OtherAllocThe other allocator.

◆ operator==() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE bool gum::List< Val, Alloc >::operator== ( const List< Val, OtherAlloc > &  src) const

Definition at line 1994 of file list_tpl.h.

1994  {
1995  // check if the two lists have at least the same number of elements
1996  if (_nb_elements_ != src._nb_elements_) return false;
1997 
1998  // parse the two lists
1999  for (ListBucket< Val >*iter1 = _deb_list_, *iter2 = src._deb_list_; iter1 != nullptr;
2000  iter1 = iter1->_next_, iter2 = iter2->_next_)
2001  if (*iter1 != *iter2) return false;
2002 
2003  return true;
2004  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

◆ operator[]() [1/2]

template<typename Val , typename Alloc >
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.

Parameters
iThe position of the element in the list (0 = first element).
Exceptions
NotFoundRaised if the element to be retrieved does not exist.
Returns
Returns a reference on the element stored at the ith position in the list.

Definition at line 2015 of file list_tpl.h.

2015  {
2016  // check if we can return the element we ask for
2017  if (i >= _nb_elements_) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
2018 
2019  return **_getIthBucket_(i);
2020  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1574

◆ operator[]() [2/2]

template<typename Val , typename Alloc >
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.

Parameters
ithe position of the element in the list (0 = first element).
Exceptions
NotFoundRaised if the element to be retrieved does not exist.
Returns
Returns a reference on the element stored at the ith position in the list.

Definition at line 2024 of file list_tpl.h.

2024  {
2025  // check if we can return the element we ask for
2026  if (i >= _nb_elements_) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
2027 
2028  return **_getIthBucket_(i);
2029  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1574

◆ popBack()

template<typename Val , typename Alloc >
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.

1884  {
1886  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ popFront()

template<typename Val , typename Alloc >
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.

1890  {
1892  }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1794

◆ push_back() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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.

Template Parameters
ArgsThe emplace arguments type.
Parameters
argsThe emplace arguments values.
Returns
Returns a reference on the copy inserted into the list.

◆ push_back() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::push_back ( Args &&...  args)

Definition at line 1548 of file list_tpl.h.

1548  {
1549  return pushBack(std::forward< Args >(args)...);
1550  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1535

◆ push_front() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
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.

Template Parameters
ArgsThe emplace values type.
Parameters
argsThe emplace values.
Returns
Returns a reference on the copy inserted into the list.

◆ push_front() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::push_front ( Args &&...  args)

Definition at line 1522 of file list_tpl.h.

1522  {
1523  return pushFront(std::forward< Args >(args)...);
1524  }
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition: list_tpl.h:1509

◆ pushBack() [1/2]

template<typename Val, typename Alloc >
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.

Parameters
valThe value pushed back.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1535 of file list_tpl.h.

1535  {
1536  return _pushBack_(_createBucket_(val));
1537  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1489

◆ pushBack() [2/2]

template<typename Val, typename Alloc >
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.

Parameters
valThe value pushed back.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1541 of file list_tpl.h.

1541  {
1542  return _pushBack_(_createBucket_(std::move(val)));
1543  }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1489

◆ pushFront() [1/2]

template<typename Val, typename Alloc >
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.

Parameters
valThe valus pushed at the front.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1509 of file list_tpl.h.

1509  {
1510  return _pushFront_(_createBucket_(val));
1511  }
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1470
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419

◆ pushFront() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::pushFront ( Val &&  val)

Inserts a new element (a move) at the beginning of the chained list.

Parameters
valThe valus pushed at the front.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1515 of file list_tpl.h.

1515  {
1516  return _pushFront_(_createBucket_(std::move(val)));
1517  }
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1470
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1419

◆ rbegin() [1/2]

template<typename Val , typename Alloc >
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.

Returns
Returns an unsafe iterator pointing to the last element of the List.

Definition at line 1401 of file list_tpl.h.

1401  {
1402  if (_nb_elements_)
1403  return ListIterator< Val >{*this, _nb_elements_ - 1};
1404  else
1405  return ListIterator< Val >{};
1406  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1437

◆ rbegin() [2/2]

template<typename Val , typename Alloc >
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.

Returns
Returns an unsafe const iterator pointing to the last element of the List.

Definition at line 1410 of file list_tpl.h.

1410  {
1411  if (_nb_elements_)
1412  return ListConstIterator< Val >{*this, _nb_elements_ - 1};
1413  else
1414  return ListConstIterator< Val >{};
1415  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ rbeginSafe()

template<typename Val , typename Alloc >
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.

Returns
Returns a safe iterator pointing to the last element of the List.

Definition at line 1383 of file list_tpl.h.

1383  {
1384  if (_nb_elements_)
1385  return ListIteratorSafe< Val >{*this, _nb_elements_ - 1};
1386  else
1387  return ListIteratorSafe< Val >{};
1388  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1439

◆ rend() [1/2]

template<typename Val , typename Alloc >
INLINE const ListIterator< Val > & gum::List< Val, Alloc >::rend ( )
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.

1332  {
1333  return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1334  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1437

◆ rend() [2/2]

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::rend ( ) const
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.

Returns
Returns an unsafe const iterator pointing just before the beginning of the List.

Definition at line 1338 of file list_tpl.h.

1338  {
1339  return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1340  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1438

◆ rendSafe()

template<typename Val , typename Alloc >
INLINE const ListIteratorSafe< Val > & gum::List< Val, Alloc >::rendSafe ( )
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.

Returns
Returns a safe iterator pointing just before the beginning of the List.

Definition at line 1320 of file list_tpl.h.

1320  {
1321  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1322  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1439

◆ size()

template<typename Val , typename Alloc >
INLINE Size gum::List< Val, Alloc >::size ( ) const
noexcept

Returns the number of elements in the list.

This method runs in constant time.

Definition at line 1779 of file list_tpl.h.

1779  {
1780  return _nb_elements_;
1781  }
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303

◆ swap()

template<typename Val , typename Alloc >
INLINE void gum::List< Val, Alloc >::swap ( List< Val, Alloc > &  other_list)

Swap the current list with another one.

Parameters
other_listThe list to swap elements with.

Definition at line 2033 of file list_tpl.h.

2033  {
2034  std::swap(_deb_list_, other_list._deb_list_);
2035  std::swap(_end_list_, other_list._end_list_);
2036  std::swap(_nb_elements_, other_list._nb_elements_);
2037  std::swap(_safe_iterators_, other_list._safe_iterators_);
2038  std::swap(_alloc_bucket_, other_list._alloc_bucket_);
2039  }
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
BucketAllocator _alloc_bucket_
The allocator for the buckets.
Definition: list.h:1309

◆ toString()

template<typename Val , typename Alloc >
std::string gum::List< Val, Alloc >::toString ( ) const

Converts a list into a string.

Returns
Returns a std::string representation of the gum::List.

Definition at line 1902 of file list_tpl.h.

1902  {
1903  bool deja = false;
1904  std::stringstream stream;
1905  stream << "[";
1906 
1907  for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_, deja = true) {
1908  if (deja) stream << " --> ";
1909 
1910  stream << ptr->_val_;
1911  }
1912 
1913  stream << "]";
1914 
1915  return stream.str();
1916  }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297

Friends And Related Function Documentation

◆ ListConstIterator< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListConstIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1438 of file list.h.

◆ ListConstIteratorSafe< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListConstIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1440 of file list.h.

◆ ListIterator< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1437 of file list.h.

◆ ListIteratorSafe< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1439 of file list.h.

Member Data Documentation

◆ _alloc_bucket_

template<typename Val, typename Alloc = std::allocator< Val >>
BucketAllocator gum::List< Val, Alloc >::_alloc_bucket_
mutableprivate

The allocator for the buckets.

Definition at line 1309 of file list.h.

◆ _deb_list_

template<typename Val, typename Alloc = std::allocator< Val >>
ListBucket< Val >* gum::List< Val, Alloc >::_deb_list_ {nullptr}
private

A pointer on the first element of the chained list.

Definition at line 1297 of file list.h.

◆ _end_list_

template<typename Val, typename Alloc = std::allocator< Val >>
ListBucket< Val >* gum::List< Val, Alloc >::_end_list_ {nullptr}
private

A pointer on the last element of the chained list.

Definition at line 1300 of file list.h.

◆ _nb_elements_

template<typename Val, typename Alloc = std::allocator< Val >>
Size gum::List< Val, Alloc >::_nb_elements_ {Size(0)}
private

The number of elements in the list.

Definition at line 1303 of file list.h.

◆ _safe_iterators_

template<typename Val, typename Alloc = std::allocator< Val >>
std::vector< const_iterator_safe* > gum::List< Val, Alloc >::_safe_iterators_
mutableprivate

The list of "safe" iterators attached to the list.

Definition at line 1306 of file list.h.


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