aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
list.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49#ifndef GUM_LIST_H
50#define GUM_LIST_H
51
52#include <cstddef>
53#include <iostream>
54#include <sstream>
55#include <vector>
56
57#include <agrum/agrum.h>
58
60
61#include <initializer_list>
62
63#define GUM_DEFAULT_ITERATOR_NUMBER 4
64
65namespace gum {
66
67 // ==============================================================================
68 // templates provided by this header
69 // ==============================================================================
70
71#ifndef DOXYGEN_SHOULD_SKIP_THIS
72
73 template < typename Val >
74 class ListBucket;
75 template < typename Val >
76 class ListIterator;
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 >
84 class List;
85
86#endif // DOXYGEN_SHOULD_SKIP_THIS
87
88#ifndef SWIG // SWIG cannot read these lines
90 template < typename Val >
91 std::ostream& operator<<(std::ostream& stream, const List< Val >& list);
92#endif // SWIG
93
94
95 // ===========================================================================
96 // === BUCKETS: SINGLE ELEMENTS OF A CHAINED LIST ===
97 // ===========================================================================
98
112 template < typename Val >
114 private:
120 enum class Emplace { EMPLACE };
121
122 public:
123 // ============================================================================
125 // ============================================================================
127
129 ListBucket() = delete;
130
135 explicit ListBucket(const Val& v);
136
141 explicit ListBucket(Val&& v) noexcept;
142
148 template < typename... Args >
149 explicit ListBucket(Emplace, Args&&... args);
150
155 ListBucket(const ListBucket< Val >& src);
156
162
172 ~ListBucket();
173
175 // ============================================================================
177 // ============================================================================
179
186
193
199 bool operator==(const ListBucket< Val >& src) const;
200
206 bool operator!=(const ListBucket< Val >& src) const;
207
209 // ============================================================================
211 // ============================================================================
213
218 Val& operator*() noexcept;
219
224 const Val& operator*() const noexcept;
225
230 const ListBucket< Val >* next() const noexcept;
231
236 const ListBucket< Val >* previous() const noexcept;
237
239
240 private:
243 friend class List< Val >;
244 friend class ListIterator< Val >;
245 friend class ListConstIterator< Val >;
246 friend class ListIteratorSafe< Val >;
247 friend class ListConstIteratorSafe< Val >;
248
251 ListBucket< Val >* _prev_{nullptr};
254
256 Val _val_;
257 };
258
259 // ===========================================================================
260 // === GENERIC DOUBLY CHAINED LISTS ===
261 // ===========================================================================
262
377 template < typename Val >
378 class List {
379 public:
382 using value_type = Val;
383 using reference = Val&;
384 using const_reference = const Val&;
385 using pointer = Val*;
386 using const_pointer = const Val*;
388 using difference_type = std::ptrdiff_t;
394
397 enum class location { BEFORE, AFTER };
398
399 // ============================================================================
401 // ============================================================================
403
407 explicit List();
408
419 List(const List< Val >& src);
420
425 List(List< Val >&& src) noexcept;
426
431 List(std::initializer_list< Val > list);
432
436 ~List();
437
439 // ============================================================================
441 // ============================================================================
443
454 const const_iterator_safe& cendSafe() const noexcept;
455
466 const iterator_safe& endSafe() noexcept;
467
480 const const_iterator_safe& crendSafe() const noexcept;
481
494 const iterator_safe& rendSafe() noexcept;
495
508 const_iterator_safe cbeginSafe() const;
509
521
534 const_iterator_safe crbeginSafe() const;
535
548
561 const const_iterator& cend() const noexcept;
562
575 const iterator& end() noexcept;
576
590 const const_iterator& end() const noexcept;
591
606 const const_iterator& crend() const noexcept;
607
622 const iterator& rend() noexcept;
623
638 const const_iterator& rend() const noexcept;
639
654 const_iterator cbegin() const;
655
669 iterator begin();
670
685 const_iterator begin() const;
686
701 const_iterator crbegin() const;
702
718
733 const_iterator rbegin() const;
734
736 // ============================================================================
738 // ============================================================================
740
754 Val& pushFront(const Val& val);
755
765 Val& pushFront(Val&& val);
766
776 template < typename... Args >
777 Val& push_front(Args&&... args);
778
788 template < typename... Args >
789 Val& emplaceFront(Args&&... args);
790
803 Val& pushBack(const Val& val);
804
817 Val& pushBack(Val&& val);
818
827 template < typename... Args >
828 Val& push_back(Args&&... args);
829
840 template < typename... Args >
841 Val& emplaceBack(Args&&... args);
842
852 Val& insert(const Val& val);
853
863 Val& insert(Val&& val);
864
878 Val& insert(Size pos, const Val& val);
879
891 Val& insert(Size pos, Val&& val);
892
903 Val& insert(const const_iterator_safe& iter, const Val& val, location place = location::BEFORE);
904
915 Val& insert(const const_iterator_safe& iter, Val&& val, location place = location::BEFORE);
916
927 Val& insert(const const_iterator& iter, const Val& val, location place = location::BEFORE);
928
939 Val& insert(const const_iterator& iter, Val&& val, location place = location::BEFORE);
940
954 template < typename... Args >
955 Val& emplace(const const_iterator& iter, Args&&... args);
956
970 template < typename... Args >
971 Val& emplace(const const_iterator_safe& iter, Args&&... args);
972
977 Val& front() const;
978
983 Val& back() const;
984
989 Size size() const noexcept;
990
1001 bool exists(const Val& val) const;
1002
1012 void erase(Size i);
1013
1023 void erase(const iterator_safe& iter);
1024
1035 void erase(const const_iterator_safe& iter);
1036
1047 void eraseByVal(const Val& val);
1048
1059 void eraseAllVal(const Val& val);
1060
1066 void popBack();
1067
1073 void popFront();
1074
1082 void clear();
1083
1088 bool empty() const noexcept;
1089
1094 void swap(List& other_list);
1095
1100 std::string toString() const;
1101
1108 template < typename Mount >
1109 List< Mount > map(Mount (*f)(Val)) const;
1110
1117 template < typename Mount >
1118 List< Mount > map(Mount (*f)(Val&)) const;
1119
1126 template < typename Mount >
1127 List< Mount > map(Mount (*f)(const Val&)) const;
1128
1136 template < typename Mount >
1137 List< Mount > map(const Mount& mount) const;
1138
1140 // ============================================================================
1142 // ============================================================================
1144
1163 List< Val >& operator=(const List< Val >& src);
1164
1171 List< Val >& operator=(List< Val >&& src);
1172
1185 Val& operator+=(const Val& val);
1186
1199 Val& operator+=(Val&& val);
1200
1209 bool operator==(const List< Val >& src) const;
1210
1219 bool operator!=(const List< Val >& src) const;
1220
1233 Val& operator[](const Size i);
1234
1247 const Val& operator[](const Size i) const;
1248
1250
1251 private:
1253 ListBucket< Val >* _deb_list_{nullptr};
1254
1257
1260
1262 mutable std::vector< const_iterator_safe* > _safe_iterators_;
1263
1272 void _copy_elements_(const List< Val >& src);
1273
1283 ListBucket< Val >* _getIthBucket_(Size i) const noexcept;
1284
1298 ListBucket< Val >* _getBucket_(const Val& val) const noexcept;
1299
1311 void _erase_(ListBucket< Val >* bucket);
1312
1318 ListBucket< Val >* _createBucket_(const Val& val) const;
1319
1325 ListBucket< Val >* _createBucket_(Val&& val) const;
1326
1333 template < typename... Args >
1334 ListBucket< Val >* _createEmplaceBucket_(Args&&... args) const;
1335
1341 Val& _pushFront_(ListBucket< Val >* new_elt);
1342
1348 Val& _pushBack_(ListBucket< Val >* new_elt);
1349
1356 Val& _insertBefore_(ListBucket< Val >* new_elt, ListBucket< Val >* current_elt);
1357
1364 Val& _insertAfter_(ListBucket< Val >* new_elt, ListBucket< Val >* current_elt);
1365
1374 Val& _insert_(const const_iterator_safe& iter, ListBucket< Val >* new_elt, location place);
1375
1384 Val& _insert_(const const_iterator& iter, ListBucket< Val >* new_elt, location place);
1385
1388 friend class ListIterator< Val >;
1389 friend class ListConstIterator< Val >;
1390 friend class ListIteratorSafe< Val >;
1391 friend class ListConstIteratorSafe< Val >;
1393 };
1394
1395 // ===========================================================================
1396 // === UNSAFE LIST CONST ITERATORS ===
1397 // ===========================================================================
1448 template < typename Val >
1450 public:
1453 using iterator_category = std::bidirectional_iterator_tag;
1454 using value_type = Val;
1455 using reference = Val&;
1456 using const_reference = const Val&;
1457 using pointer = Val*;
1458 using const_pointer = const Val*;
1459 using difference_type = std::ptrdiff_t;
1461
1462 // ============================================================================
1464 // ============================================================================
1466
1472 explicit ListConstIterator() noexcept;
1473
1474#ifndef DOXYGEN_SHOULD_SKIP_THIS
1475 // constructor for the static cend/crend iterator
1476 // only list.cpp should use this constructor
1477 explicit consteval ListConstIterator(StaticInitializer init) noexcept {}
1478#endif // DOXYGEN_SHOULD_SKIP_THIS
1479
1483 ListConstIterator(const List< Val >& theList) noexcept;
1484
1489 ListConstIterator(const ListConstIterator< Val >& src) noexcept;
1490
1496
1505 ListConstIterator(const List< Val >& theList, Size ind_elt);
1506
1510 ~ListConstIterator() noexcept;
1511
1513 // ============================================================================
1515 // ============================================================================
1517
1525 void clear() noexcept;
1526
1530 void setToEnd() noexcept;
1531
1538 bool isEnd() const noexcept;
1539
1541 // ============================================================================
1543 // ============================================================================
1545
1554 ListConstIterator< Val >& operator=(const ListConstIterator< Val >& src) noexcept;
1555
1562 ListConstIterator< Val >& operator=(ListConstIterator< Val >&& src) noexcept;
1563
1577 ListConstIterator< Val >& operator++() noexcept;
1578
1584 ListConstIterator< Val >& operator+=(difference_type i) noexcept;
1585
1599 ListConstIterator< Val >& operator--() noexcept;
1600
1607 ListConstIterator< Val >& operator-=(difference_type i) noexcept;
1608
1615 ListConstIterator< Val > operator+(difference_type i) noexcept;
1616
1623 ListConstIterator< Val > operator-(difference_type i) noexcept;
1624
1634 bool operator!=(const ListConstIterator< Val >& src) const noexcept;
1635
1645 bool operator==(const ListConstIterator< Val >& src) const noexcept;
1646
1652 const Val& operator*() const;
1653
1659 const Val* operator->() const;
1660
1662
1663 private:
1668 friend class List< Val >;
1669
1671 ListBucket< Val >* _bucket_{nullptr};
1672
1674 ListBucket< Val >* _getBucket_() const noexcept;
1675 };
1676
1678 template < typename Val >
1679 typename ListConstIterator< Val >::difference_type
1680 operator-(const ListConstIterator< Val >& iter1, const ListConstIterator< Val >& iter2);
1681
1682 // ===========================================================================
1683 // === UNSAFE LIST ITERATORS ===
1684 // ===========================================================================
1685
1735 template < typename Val >
1736 class ListIterator: public ListConstIterator< Val > {
1737 public:
1740 using iterator_category = std::bidirectional_iterator_tag;
1741 using value_type = Val;
1742 using reference = Val&;
1743 using const_reference = const Val&;
1744 using pointer = Val*;
1745 using const_pointer = const Val*;
1746 using difference_type = std::ptrdiff_t;
1748
1749 // ============================================================================
1751 // ============================================================================
1753
1759 explicit ListIterator() noexcept;
1760
1761#ifndef DOXYGEN_SHOULD_SKIP_THIS
1762 // constructor for the static end/rend iterator
1763 // only list.cpp should use this constructor
1764 explicit consteval ListIterator(StaticInitializer init) noexcept :
1766#endif // DOXYGEN_SHOULD_SKIP_THIS
1767
1772 ListIterator(const List< Val >& theList) noexcept;
1773
1778 ListIterator(const ListIterator< Val >& src) noexcept;
1779
1784 ListIterator(ListIterator< Val >&& src) noexcept;
1785
1794 ListIterator(const List< Val >& theList, Size ind_elt);
1795
1799 ~ListIterator() noexcept;
1800
1802 // ============================================================================
1804 // ============================================================================
1806
1807 using ListConstIterator< Val >::clear;
1808 using ListConstIterator< Val >::setToEnd;
1809 using ListConstIterator< Val >::isEnd;
1810
1812
1813 // ============================================================================
1815 // ============================================================================
1817
1826 ListIterator< Val >& operator=(const ListIterator< Val >& src) noexcept;
1827
1829
1837 ListIterator< Val >& operator=(ListIterator< Val >&& src) noexcept;
1838
1853 ListIterator< Val >& operator++() noexcept;
1854
1860 ListIterator< Val >& operator+=(difference_type i) noexcept;
1861
1875 ListIterator< Val >& operator--() noexcept;
1876
1883 ListIterator< Val >& operator-=(difference_type i) noexcept;
1884
1891 ListIterator< Val > operator+(difference_type i) noexcept;
1892
1899 ListIterator< Val > operator-(difference_type i) noexcept;
1900
1910 bool operator==(const ListIterator< Val >& src) const noexcept;
1911
1921 bool operator!=(const ListIterator< Val >& src) const noexcept;
1922
1928 const Val& operator*() const;
1929
1936 Val& operator*();
1937
1943 const Val* operator->() const;
1944
1951 Val* operator->();
1952
1954 };
1955
1956 // ===========================================================================
1957 // === LIST CONST ITERATORS ===
1958 // ===========================================================================
2004 template < typename Val >
2006 public:
2009 using iterator_category = std::bidirectional_iterator_tag;
2010 using value_type = Val;
2011 using reference = Val&;
2012 using const_reference = const Val&;
2013 using pointer = Val*;
2014 using const_pointer = const Val*;
2015 using difference_type = std::ptrdiff_t;
2017
2018 // ============================================================================
2020 // ============================================================================
2022
2028 explicit ListConstIteratorSafe() noexcept;
2029
2030#ifndef DOXYGEN_SHOULD_SKIP_THIS
2031 // constructor for the static cendSafe/crendSafe iterator
2032 // only list.cpp should use this constructor
2033 explicit consteval ListConstIteratorSafe(StaticInitializer init) noexcept {}
2034#endif // DOXYGEN_SHOULD_SKIP_THIS
2035
2039 ListConstIteratorSafe(const List< Val >& theList);
2040
2046
2055 ListConstIteratorSafe(const List< Val >& theList, Size ind_elt);
2056
2062
2067
2069 // ============================================================================
2071 // ============================================================================
2073
2082 void clear();
2083
2087 void setToEnd();
2088
2095 bool isEnd() const;
2096
2098 // ============================================================================
2100 // ============================================================================
2102
2112
2120
2135
2141 ListConstIteratorSafe< Val >& operator+=(difference_type i) noexcept;
2142
2156 ListConstIteratorSafe< Val >& operator--() noexcept;
2157
2164 ListConstIteratorSafe< Val >& operator-=(difference_type i) noexcept;
2165
2172 ListConstIteratorSafe< Val > operator+(difference_type i) noexcept;
2173
2180 ListConstIteratorSafe< Val > operator-(difference_type i) noexcept;
2181
2191 bool operator!=(const ListConstIteratorSafe< Val >& src) const;
2192
2202 bool operator==(const ListConstIteratorSafe< Val >& src) const;
2203
2209 const Val& operator*() const;
2210
2216 const Val* operator->() const;
2217
2219
2220 private:
2224 friend class List< Val >;
2225 friend class ListConstIterator< Val >;
2227
2229 const List< Val >* _list_{nullptr};
2230
2233
2237
2241
2243 bool _null_pointing_{false};
2244
2246 ListBucket< Val >* _getBucket_() const noexcept;
2247
2249 void _removeFromSafeList_() const;
2250
2252 ListConstIteratorSafe< Val >& _opPlus_(Size i) noexcept;
2253
2255 ListConstIteratorSafe< Val >& _opMinus_(Size i) noexcept;
2256 };
2257
2259 template < typename Val >
2260 typename ListConstIteratorSafe< Val >::difference_type
2261 operator-(const ListConstIteratorSafe< Val >& iter1,
2262 const ListConstIteratorSafe< Val >& iter2);
2263
2264 // ===========================================================================
2265 // === LIST ITERATORS ===
2266 // ===========================================================================
2267
2317 template < typename Val >
2319 public:
2322 using iterator_category = std::bidirectional_iterator_tag;
2323 using value_type = Val;
2324 using reference = Val&;
2325 using const_reference = const Val&;
2326 using pointer = Val*;
2327 using const_pointer = const Val*;
2328 using difference_type = std::ptrdiff_t;
2330
2331 // ============================================================================
2333 // ============================================================================
2335
2341 explicit ListIteratorSafe() noexcept;
2342
2343#ifndef DOXYGEN_SHOULD_SKIP_THIS
2344 // constructor for the static endSafe/rendSafe iterator
2345 // only list.cpp should use this constructor
2346 explicit consteval ListIteratorSafe(StaticInitializer init) noexcept :
2348#endif // DOXYGEN_SHOULD_SKIP_THIS
2349
2353 ListIteratorSafe(const List< Val >& theList);
2354
2360
2369 ListIteratorSafe(const List< Val >& theList, Size ind_elt);
2370
2376
2381
2383 // ============================================================================
2385 // ============================================================================
2387
2388 using ListConstIteratorSafe< Val >::clear;
2390 using ListConstIteratorSafe< Val >::isEnd;
2391
2393 // ============================================================================
2395 // ============================================================================
2397
2407
2415
2430
2436 ListIteratorSafe< Val >& operator+=(difference_type i) noexcept;
2437
2451 ListIteratorSafe< Val >& operator--() noexcept;
2452
2459 ListIteratorSafe< Val >& operator-=(difference_type i) noexcept;
2460
2467 ListIteratorSafe< Val > operator+(difference_type i) noexcept;
2468
2475 ListIteratorSafe< Val > operator-(difference_type i) noexcept;
2476
2482 Val& operator*();
2483
2489 Val* operator->();
2490
2500 bool operator!=(const ListIteratorSafe< Val >& src) const;
2501
2511 bool operator==(const ListIteratorSafe< Val >& src) const;
2512
2518 const Val& operator*() const;
2519
2525 const Val* operator->() const;
2526 };
2527
2528#ifndef DOXYGEN_SHOULD_SKIP_THIS
2529 // _static_list_end_ is a 'constant' iterator initialized at compile time
2530 // that represents the end iterators for all lists (whatever their content).
2531 // This global variable avoids creating the same iterators within every
2532 // List instance (this would be quite inefficient as end is precisely
2533 // identical for all lists). The same holds for reverse and safe end iterators.
2534 // The type of _list_end_ is a pointer to void because C++ allows
2535 // pointers to void to be cast into pointers to other types (and conversely).
2536 // This avoids the painful strict-aliasing rule warning
2537 extern const ListConstIteratorSafe< Debug > _static_list_end_safe_;
2538 extern const ListConstIterator< Debug > _static_list_end_;
2539
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_;
2542#endif // DOXYGEN_SHOULD_SKIP_THIS
2543
2544} /* namespace gum */
2545
2546
2547#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
2548extern template class gum::List< bool >;
2549extern template class gum::List< int >;
2550extern template class gum::List< unsigned int >;
2551#endif
2552
2553
2554// always include the implementation of the templates
2556
2557#endif /* GUM_LIST_H */
Bucket for a chained list.
Definition list.h:113
Val _val_
Val is the value contained in the box.
Definition list.h:256
Val & operator*() noexcept
Dereferencing operator.
Definition list_tpl.h:131
const ListBucket< Val > * next() const noexcept
Returns the bucket toward the next element.
Definition list_tpl.h:137
ListBucket< Val > * _next_
Chaining toward the adjacent elements.
Definition list.h:252
const ListBucket< Val > * previous() const noexcept
Returns the bucket toward the preceding element.
Definition list_tpl.h:143
ListBucket< Val > & operator=(const ListBucket< Val > &src)
Copy operator.
Definition list_tpl.h:94
ListBucket()=delete
Removes empty constructor.
bool operator!=(const ListBucket< Val > &src) const
Inequality check.
Definition list_tpl.h:119
Emplace
C dummy type for the emplace constructor.
Definition list.h:120
bool operator==(const ListBucket< Val > &src) const
Equality check.
Definition list_tpl.h:113
~ListBucket()
Class destructor.
Definition list_tpl.h:106
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.
Definition list.h:251
ListBucket< Val > & operator=(ListBucket< Val > &&src)=delete
Move operator.
Safe const iterators for Lists.
Definition list.h:2005
Val value_type
Types for STL compliance.
Definition list.h:2010
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition list.h:2232
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:2015
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:2009
Val * pointer
Types for STL compliance.
Definition list.h:2013
ListConstIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:507
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 ++.
Definition list.h:2236
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 –.
Definition list.h:2240
const Val & const_reference
Types for STL compliance.
Definition list.h:2012
const Val * const_pointer
Types for STL compliance.
Definition list.h:2014
const List< Val > * _list_
The list the iterator is pointing to.
Definition list.h:2229
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition list.h:2243
Val & reference
Types for STL compliance.
Definition list.h:2011
Unsafe but fast const iterators for Lists.
Definition list.h:1449
const Val * const_pointer
Types for STL compliance.
Definition list.h:1458
ListBucket< Val > * _getBucket_() const noexcept
Returns the bucket the iterator is pointing to.
Definition list_tpl.h:238
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition list.h:1671
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:1459
Val value_type
Types for STL compliance.
Definition list.h:1454
bool isEnd() const noexcept
Returns a bool indicating whether the iterator points to the end of the list.
Definition list_tpl.h:257
void clear() noexcept
Makes the iterator point toward nothing.
Definition list_tpl.h:244
const Val & const_reference
Types for STL compliance.
Definition list.h:1456
ListConstIterator< Val > & operator=(const ListConstIterator< Val > &src) noexcept
Copy operator.
Definition list_tpl.h:218
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:1453
ListConstIterator< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
Definition list_tpl.h:263
void setToEnd() noexcept
Positions the iterator to the end of the list.
Definition list_tpl.h:250
ListConstIterator() noexcept
Default constructor.
Definition list_tpl.h:155
Val & reference
Types for STL compliance.
Definition list.h:1455
~ListConstIterator() noexcept
Class Desctructor.
Definition list_tpl.h:210
Val * pointer
Types for STL compliance.
Definition list.h:1457
Safe iterators for Lists.
Definition list.h:2318
Val * pointer
Types for STL compliance.
Definition list.h:2326
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:2328
Val value_type
Types for STL compliance.
Definition list.h:2323
const Val * const_pointer
Types for STL compliance.
Definition list.h:2327
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:2322
ListIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:962
Val & reference
Types for STL compliance.
Definition list.h:2324
const Val & const_reference
Types for STL compliance.
Definition list.h:2325
Unsafe but fast iterators for Lists.
Definition list.h:1736
Val value_type
Types for STL compliance.
Definition list.h:1741
const Val * const_pointer
Types for STL compliance.
Definition list.h:1745
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:1746
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:1740
Val & reference
Types for STL compliance.
Definition list.h:1742
ListIterator() noexcept
Default constructor.
Definition list_tpl.h:364
Val * pointer
Types for STL compliance.
Definition list.h:1744
const Val & const_reference
Types for STL compliance.
Definition list.h:1743
Generic doubly linked lists.
Definition list.h:378
Val & emplaceFront(Args &&... args)
Emplace elements at the beginning of the chained list.
Definition list_tpl.h:1475
std::vector< const_iterator_safe * > _safe_iterators_
The list of "safe" iterators attached to the list.
Definition list.h:1262
Size size() const noexcept
Returns the number of elements in the list.
Definition list_tpl.h:1710
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1323
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
Definition list_tpl.h:1386
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1347
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition list_tpl.h:1420
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition list_tpl.h:1400
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:392
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:388
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition list_tpl.h:1455
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1389
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
Definition list_tpl.h:1287
location
Locations around iterators where insertions of new elements can take / place.
Definition list.h:397
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:1587
Val & push_front(Args &&... args)
An alias for pushFront used for STL compliance.
Definition list_tpl.h:1468
Val & back() const
Returns a reference to last element of a list, if any.
Definition list_tpl.h:1702
Val * pointer
Types for STL compliance.
Definition list.h:385
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition list_tpl.h:1725
void clear()
Deletes all the elements of a chained list.
Definition list_tpl.h:1147
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1390
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1391
Val & front() const
Returns a reference to first element of a list, if any.
Definition list_tpl.h:1694
std::string toString() const
Converts a list into a string.
Definition list_tpl.h:1828
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
Definition list_tpl.h:1413
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1311
ListIterator< Val > iterator
Types for STL compliance.
Definition list.h:389
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
Definition list_tpl.h:1341
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1388
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
Definition list_tpl.h:1847
Val & push_back(Args &&... args)
An alias for pushBack used for STL compliance.
Definition list_tpl.h:1494
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1481
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition list_tpl.h:1520
Val & emplaceBack(Args &&... args)
Emplace elements at the end of the chained list.
Definition list_tpl.h:1501
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1335
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition list.h:1253
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition list_tpl.h:1293
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition list_tpl.h:1437
Val value_type
Types for STL compliance.
Definition list.h:382
void popBack()
Removes the last element of a List, if any.
Definition list_tpl.h:1810
List()
A basic constructor that creates an empty list.
Definition list_tpl.h:1167
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1317
const Val & const_reference
Types for STL compliance.
Definition list.h:384
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition list_tpl.h:1784
void swap(List &other_list)
Swap the current list with another one.
Definition list_tpl.h:1957
Size size_type
Types for STL compliance.
Definition list.h:387
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
Definition list.h:391
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition list_tpl.h:1353
void eraseAllVal(const Val &val)
erases all the elements encountered with a given value
Definition list_tpl.h:1799
const Val * const_pointer
Types for STL compliance.
Definition list.h:386
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition list_tpl.h:1551
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition list_tpl.h:1508
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition list_tpl.h:1822
Size _nb_elements_
The number of elements in the list.
Definition list.h:1259
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
Definition list_tpl.h:1108
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
Definition list_tpl.h:1716
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1365
~List()
Class destructor.
Definition list_tpl.h:1220
Val & emplace(const const_iterator &iter, Args &&... args)
Emplace a new element before a given iterator.
Definition list_tpl.h:1681
void popFront()
Removes the first element of a List, if any.
Definition list_tpl.h:1816
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
Definition list_tpl.h:1379
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1275
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
Definition list_tpl.h:1793
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
Definition list_tpl.h:1372
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition list_tpl.h:1534
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition list.h:390
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1305
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition list.h:1256
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Definition list_tpl.h:1281
Val & reference
Types for STL compliance.
Definition list.h:383
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
Definition list_tpl.h:1763
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
template implementation of chained lists
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
STL namespace.
Data types to enable creating static variables at compile time.