61#include <initializer_list>
63#define GUM_DEFAULT_ITERATOR_NUMBER 4
71#ifndef DOXYGEN_SHOULD_SKIP_THIS
73 template <
typename Val >
75 template <
typename Val >
77 template <
typename Val >
78 class ListConstIterator;
79 template <
typename Val >
80 class ListIteratorSafe;
81 template <
typename Val >
82 class ListConstIteratorSafe;
83 template <
typename Val >
90 template < typename Val >
91 std::ostream&
operator<<(std::ostream& stream,
const List< Val >& list);
112 template <
typename Val >
148 template <
typename... Args >
224 const Val& operator*() const noexcept;
377 template <
typename Val >
431 List(std::initializer_list< Val > list);
454 const const_iterator_safe&
cendSafe() const noexcept;
480 const const_iterator_safe&
crendSafe() const noexcept;
561 const const_iterator&
cend() const noexcept;
590 const const_iterator&
end() const noexcept;
606 const const_iterator&
crend() const noexcept;
638 const const_iterator&
rend() const noexcept;
654 const_iterator
cbegin() const;
685 const_iterator
begin() const;
701 const_iterator
crbegin() const;
733 const_iterator
rbegin() const;
776 template < typename... Args >
788 template < typename... Args >
827 template < typename... Args >
840 template < typename... Args >
852 Val&
insert(const Val& val);
954 template < typename... Args >
955 Val&
emplace(const const_iterator& iter, Args&&... args);
970 template < typename... Args >
971 Val&
emplace(const const_iterator_safe& iter, Args&&... args);
1001 bool exists(const Val& val) const;
1035 void erase(const const_iterator_safe& iter);
1088 bool empty() const noexcept;
1108 template < typename Mount >
1109 List< Mount >
map(Mount (*f)(Val)) const;
1117 template < typename Mount >
1118 List< Mount >
map(Mount (*f)(Val&)) const;
1126 template < typename Mount >
1127 List< Mount >
map(Mount (*f)(const Val&)) const;
1136 template < typename Mount >
1137 List< Mount >
map(const Mount& mount) const;
1163 List< Val >& operator=(const
List< Val >& src);
1171 List< Val >& operator=(
List< Val >&& src);
1185 Val& operator+=(const Val& val);
1199 Val& operator+=(Val&& val);
1209 bool operator==(const
List< Val >& src) const;
1219 bool operator!=(const
List< Val >& src) const;
1233 Val& operator[](const
Size i);
1247 const Val& operator[](const
Size i) const;
1333 template <
typename... Args >
1448 template <
typename Val >
1474#ifndef DOXYGEN_SHOULD_SKIP_THIS
1525 void clear() noexcept;
1538 bool isEnd() const noexcept;
1652 const Val& operator*() const;
1659 const Val* operator->() const;
1678 template < typename Val >
1735 template < typename Val >
1761#ifndef DOXYGEN_SHOULD_SKIP_THIS
1910 bool operator==(const
ListIterator< Val >& src) const noexcept;
1921 bool operator!=(const
ListIterator< Val >& src) const noexcept;
1928 const Val& operator*() const;
1943 const Val* operator->() const;
2004 template < typename Val >
2030#ifndef DOXYGEN_SHOULD_SKIP_THIS
2209 const Val& operator*() const;
2216 const Val* operator->() const;
2249 void _removeFromSafeList_() const;
2259 template < typename Val >
2317 template < typename Val >
2343#ifndef DOXYGEN_SHOULD_SKIP_THIS
2518 const Val& operator*() const;
2525 const Val* operator->() const;
2528#ifndef DOXYGEN_SHOULD_SKIP_THIS
2540 inline constexpr void*
const _list_end_safe_ = (
void*
const)&_static_list_end_safe_;
2541 inline constexpr void*
const _list_end_ = (
void*
const)&_static_list_end_;
2547#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Bucket for a chained list.
Val _val_
Val is the value contained in the box.
Val & operator*() noexcept
Dereferencing operator.
const ListBucket< Val > * next() const noexcept
Returns the bucket toward the next element.
ListBucket< Val > * _next_
Chaining toward the adjacent elements.
const ListBucket< Val > * previous() const noexcept
Returns the bucket toward the preceding element.
ListBucket< Val > & operator=(const ListBucket< Val > &src)
Copy operator.
ListBucket()=delete
Removes empty constructor.
bool operator!=(const ListBucket< Val > &src) const
Inequality check.
Emplace
C dummy type for the emplace constructor.
bool operator==(const ListBucket< Val > &src) const
Equality check.
~ListBucket()
Class destructor.
ListBucket(ListBucket< Val > &&src)=delete
Move constructor should be useless.
ListBucket(Emplace, Args &&... args)
Emplace (universal) constructor.
ListBucket< Val > * _prev_
Chaining toward the adjacent elements.
ListBucket< Val > & operator=(ListBucket< Val > &&src)=delete
Move operator.
Safe const iterators for Lists.
Val value_type
Types for STL compliance.
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
std::ptrdiff_t difference_type
Types for STL compliance.
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Val * pointer
Types for STL compliance.
ListConstIteratorSafe() noexcept
Default constructor.
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++.
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –.
const Val & const_reference
Types for STL compliance.
const Val * const_pointer
Types for STL compliance.
const List< Val > * _list_
The list the iterator is pointing to.
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Val & reference
Types for STL compliance.
Unsafe but fast const iterators for Lists.
const Val * const_pointer
Types for STL compliance.
ListBucket< Val > * _getBucket_() const noexcept
Returns the bucket the iterator is pointing to.
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
std::ptrdiff_t difference_type
Types for STL compliance.
Val value_type
Types for STL compliance.
bool isEnd() const noexcept
Returns a bool indicating whether the iterator points to the end of the list.
void clear() noexcept
Makes the iterator point toward nothing.
const Val & const_reference
Types for STL compliance.
ListConstIterator< Val > & operator=(const ListConstIterator< Val > &src) noexcept
Copy operator.
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
ListConstIterator< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
void setToEnd() noexcept
Positions the iterator to the end of the list.
ListConstIterator() noexcept
Default constructor.
Val & reference
Types for STL compliance.
~ListConstIterator() noexcept
Class Desctructor.
Val * pointer
Types for STL compliance.
Safe iterators for Lists.
Val * pointer
Types for STL compliance.
std::ptrdiff_t difference_type
Types for STL compliance.
Val value_type
Types for STL compliance.
const Val * const_pointer
Types for STL compliance.
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
ListIteratorSafe() noexcept
Default constructor.
Val & reference
Types for STL compliance.
const Val & const_reference
Types for STL compliance.
Unsafe but fast iterators for Lists.
Val value_type
Types for STL compliance.
const Val * const_pointer
Types for STL compliance.
std::ptrdiff_t difference_type
Types for STL compliance.
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Val & reference
Types for STL compliance.
ListIterator() noexcept
Default constructor.
Val * pointer
Types for STL compliance.
const Val & const_reference
Types for STL compliance.
Generic doubly linked lists.
Val & emplaceFront(Args &&... args)
Emplace elements at the beginning of the chained list.
std::vector< const_iterator_safe * > _safe_iterators_
The list of "safe" iterators attached to the list.
Size size() const noexcept
Returns the number of elements in the list.
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
std::ptrdiff_t difference_type
Types for STL compliance.
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
location
Locations around iterators where insertions of new elements can take / place.
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.
Val & push_front(Args &&... args)
An alias for pushFront used for STL compliance.
Val & back() const
Returns a reference to last element of a list, if any.
Val * pointer
Types for STL compliance.
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
void clear()
Deletes all the elements of a chained list.
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Val & front() const
Returns a reference to first element of a list, if any.
std::string toString() const
Converts a list into a string.
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
ListIterator< Val > iterator
Types for STL compliance.
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
Val & push_back(Args &&... args)
An alias for pushBack used for STL compliance.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Val & emplaceBack(Args &&... args)
Emplace elements at the end of the chained list.
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Val value_type
Types for STL compliance.
void popBack()
Removes the last element of a List, if any.
List()
A basic constructor that creates an empty list.
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
const Val & const_reference
Types for STL compliance.
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
void swap(List &other_list)
Swap the current list with another one.
Size size_type
Types for STL compliance.
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
void eraseAllVal(const Val &val)
erases all the elements encountered with a given value
const Val * const_pointer
Types for STL compliance.
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Size _nb_elements_
The number of elements in the list.
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Val & emplace(const const_iterator &iter, Args &&... args)
Emplace a new element before a given iterator.
void popFront()
Removes the first element of a List, if any.
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
ListConstIterator< Val > const_iterator
Types for STL compliance.
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Val & reference
Types for STL compliance.
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
std::size_t Size
In aGrUM, hashed values are unsigned long int.
template implementation of chained lists
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Data types to enable creating static variables at compile time.