aGrUM 2.3.2
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-2025 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-2025 *
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
61
62#include <initializer_list>
63
64#define GUM_DEFAULT_ITERATOR_NUMBER 4
65
66namespace gum {
67
68 // ==============================================================================
69 // templates provided by this header
70 // ==============================================================================
71
72#ifndef DOXYGEN_SHOULD_SKIP_THIS
73
74 template < typename Val >
75 class ListBucket;
76 template < typename Val >
77 class ListIterator;
78 template < typename Val >
79 class ListConstIterator;
80 template < typename Val >
81 class ListIteratorSafe;
82 template < typename Val >
83 class ListConstIteratorSafe;
84 template < typename Val >
85 class List;
86
87#endif // DOXYGEN_SHOULD_SKIP_THIS
88
89#ifndef SWIG // SWIG cannot read these lines
91 template < typename Val >
92 std::ostream& operator<<(std::ostream& stream, const List< Val >& list);
93#endif // SWIG
94
95
96 // ===========================================================================
97 // === BUCKETS: SINGLE ELEMENTS OF A CHAINED LIST ===
98 // ===========================================================================
99
113 template < typename Val >
115 private:
121 enum class Emplace { EMPLACE };
122
123 public:
124 // ============================================================================
126 // ============================================================================
128
130 ListBucket() = delete;
131
136 explicit ListBucket(const Val& v);
137
142 explicit ListBucket(Val&& v) noexcept;
143
149 template < typename... Args >
150 explicit ListBucket(Emplace, Args&&... args);
151
156 ListBucket(const ListBucket< Val >& src);
157
163
173 ~ListBucket();
174
176 // ============================================================================
178 // ============================================================================
180
187
194
200 bool operator==(const ListBucket< Val >& src) const;
201
207 bool operator!=(const ListBucket< Val >& src) const;
208
210 // ============================================================================
212 // ============================================================================
214
219 Val& operator*() noexcept;
220
225 const Val& operator*() const noexcept;
226
231 const ListBucket< Val >* next() const noexcept;
232
237 const ListBucket< Val >* previous() const noexcept;
238
240
241 private:
244 friend class List< Val >;
245 friend class ListIterator< Val >;
246 friend class ListConstIterator< Val >;
247 friend class ListIteratorSafe< Val >;
248 friend class ListConstIteratorSafe< Val >;
249
252 ListBucket< Val >* _prev_{nullptr};
255
257 Val _val_;
258 };
259
260 // ===========================================================================
261 // === GENERIC DOUBLY CHAINED LISTS ===
262 // ===========================================================================
263
378 template < typename Val >
379 class List {
380 public:
383 using value_type = Val;
384 using reference = Val&;
385 using const_reference = const Val&;
386 using pointer = Val*;
387 using const_pointer = const Val*;
389 using difference_type = std::ptrdiff_t;
395
398 enum class location { BEFORE, AFTER };
399
400 // ============================================================================
402 // ============================================================================
404
408 explicit List();
409
420 List(const List< Val >& src);
421
426 List(List< Val >&& src) noexcept;
427
432 List(std::initializer_list< Val > list);
433
437 ~List();
438
440 // ============================================================================
442 // ============================================================================
444
455 const const_iterator_safe& cendSafe() const noexcept;
456
467 const iterator_safe& endSafe() noexcept;
468
481 const const_iterator_safe& crendSafe() const noexcept;
482
495 const iterator_safe& rendSafe() noexcept;
496
509 const_iterator_safe cbeginSafe() const;
510
522
535 const_iterator_safe crbeginSafe() const;
536
549
562 const const_iterator& cend() const noexcept;
563
576 const iterator& end() noexcept;
577
591 const const_iterator& end() const noexcept;
592
607 const const_iterator& crend() const noexcept;
608
623 const iterator& rend() noexcept;
624
639 const const_iterator& rend() const noexcept;
640
655 const_iterator cbegin() const;
656
670 iterator begin();
671
686 const_iterator begin() const;
687
702 const_iterator crbegin() const;
703
719
734 const_iterator rbegin() const;
735
737 // ============================================================================
739 // ============================================================================
741
755 Val& pushFront(const Val& val);
756
766 Val& pushFront(Val&& val);
767
777 template < typename... Args >
778 Val& push_front(Args&&... args);
779
789 template < typename... Args >
790 Val& emplaceFront(Args&&... args);
791
804 Val& pushBack(const Val& val);
805
818 Val& pushBack(Val&& val);
819
828 template < typename... Args >
829 Val& push_back(Args&&... args);
830
841 template < typename... Args >
842 Val& emplaceBack(Args&&... args);
843
853 Val& insert(const Val& val);
854
864 Val& insert(Val&& val);
865
879 Val& insert(Size pos, const Val& val);
880
892 Val& insert(Size pos, Val&& val);
893
904 Val& insert(const const_iterator_safe& iter, const Val& val, location place = location::BEFORE);
905
916 Val& insert(const const_iterator_safe& iter, Val&& val, location place = location::BEFORE);
917
928 Val& insert(const const_iterator& iter, const Val& val, location place = location::BEFORE);
929
940 Val& insert(const const_iterator& iter, Val&& val, location place = location::BEFORE);
941
955 template < typename... Args >
956 Val& emplace(const const_iterator& iter, Args&&... args);
957
971 template < typename... Args >
972 Val& emplace(const const_iterator_safe& iter, Args&&... args);
973
978 Val& front() const;
979
984 Val& back() const;
985
990 Size size() const noexcept;
991
1002 bool exists(const Val& val) const;
1003
1013 void erase(Size i);
1014
1024 void erase(const iterator_safe& iter);
1025
1036 void erase(const const_iterator_safe& iter);
1037
1048 void eraseByVal(const Val& val);
1049
1060 void eraseAllVal(const Val& val);
1061
1067 void popBack();
1068
1074 void popFront();
1075
1083 void clear();
1084
1089 bool empty() const noexcept;
1090
1095 void swap(List& other_list);
1096
1101 std::string toString() const;
1102
1109 template < typename Mount >
1110 List< Mount > map(Mount (*f)(Val)) const;
1111
1118 template < typename Mount >
1119 List< Mount > map(Mount (*f)(Val&)) const;
1120
1127 template < typename Mount >
1128 List< Mount > map(Mount (*f)(const Val&)) const;
1129
1137 template < typename Mount >
1138 List< Mount > map(const Mount& mount) const;
1139
1141 // ============================================================================
1143 // ============================================================================
1145
1164 List< Val >& operator=(const List< Val >& src);
1165
1172 List< Val >& operator=(List< Val >&& src);
1173
1186 Val& operator+=(const Val& val);
1187
1200 Val& operator+=(Val&& val);
1201
1210 bool operator==(const List< Val >& src) const;
1211
1220 bool operator!=(const List< Val >& src) const;
1221
1234 Val& operator[](const Size i);
1235
1248 const Val& operator[](const Size i) const;
1249
1251
1252 private:
1254 ListBucket< Val >* _deb_list_{nullptr};
1255
1258
1261
1263 mutable std::vector< const_iterator_safe* > _safe_iterators_;
1264
1273 void _copy_elements_(const List< Val >& src);
1274
1284 ListBucket< Val >* _getIthBucket_(Size i) const noexcept;
1285
1299 ListBucket< Val >* _getBucket_(const Val& val) const noexcept;
1300
1312 void _erase_(ListBucket< Val >* bucket);
1313
1319 ListBucket< Val >* _createBucket_(const Val& val) const;
1320
1326 ListBucket< Val >* _createBucket_(Val&& val) const;
1327
1334 template < typename... Args >
1336
1342 Val& _pushFront_(ListBucket< Val >* new_elt);
1343
1349 Val& _pushBack_(ListBucket< Val >* new_elt);
1350
1357 Val& _insertBefore_(ListBucket< Val >* new_elt, ListBucket< Val >* current_elt);
1358
1365 Val& _insertAfter_(ListBucket< Val >* new_elt, ListBucket< Val >* current_elt);
1366
1375 Val& _insert_(const const_iterator_safe& iter, ListBucket< Val >* new_elt, location place);
1376
1385 Val& _insert_(const const_iterator& iter, ListBucket< Val >* new_elt, location place);
1386
1389 friend class ListIterator< Val >;
1390 friend class ListConstIterator< Val >;
1391 friend class ListIteratorSafe< Val >;
1392 friend class ListConstIteratorSafe< Val >;
1394 };
1395
1396 // ===========================================================================
1397 // === UNSAFE LIST CONST ITERATORS ===
1398 // ===========================================================================
1449 template < typename Val >
1451 public:
1454 using iterator_category = std::bidirectional_iterator_tag;
1455 using value_type = Val;
1456 using reference = Val&;
1457 using const_reference = const Val&;
1458 using pointer = Val*;
1459 using const_pointer = const Val*;
1460 using difference_type = std::ptrdiff_t;
1462
1463 // ============================================================================
1465 // ============================================================================
1467
1473 explicit ListConstIterator() noexcept;
1474
1475#ifndef DOXYGEN_SHOULD_SKIP_THIS
1476 // constructor for the static cend/crend iterator
1477 // only list.cpp should use this constructor
1478 explicit consteval ListConstIterator(StaticInitializer init) noexcept {}
1479#endif // DOXYGEN_SHOULD_SKIP_THIS
1480
1484 ListConstIterator(const List< Val >& theList) noexcept;
1485
1490 ListConstIterator(const ListConstIterator< Val >& src) noexcept;
1491
1497
1506 ListConstIterator(const List< Val >& theList, Size ind_elt);
1507
1511 ~ListConstIterator() noexcept;
1512
1514 // ============================================================================
1516 // ============================================================================
1518
1526 void clear() noexcept;
1527
1531 void setToEnd() noexcept;
1532
1539 bool isEnd() const noexcept;
1540
1542 // ============================================================================
1544 // ============================================================================
1546
1555 ListConstIterator< Val >& operator=(const ListConstIterator< Val >& src) noexcept;
1556
1563 ListConstIterator< Val >& operator=(ListConstIterator< Val >&& src) noexcept;
1564
1578 ListConstIterator< Val >& operator++() noexcept;
1579
1585 ListConstIterator< Val >& operator+=(difference_type i) noexcept;
1586
1600 ListConstIterator< Val >& operator--() noexcept;
1601
1608 ListConstIterator< Val >& operator-=(difference_type i) noexcept;
1609
1616 ListConstIterator< Val > operator+(difference_type i) noexcept;
1617
1624 ListConstIterator< Val > operator-(difference_type i) noexcept;
1625
1635 bool operator!=(const ListConstIterator< Val >& src) const noexcept;
1636
1646 bool operator==(const ListConstIterator< Val >& src) const noexcept;
1647
1653 const Val& operator*() const;
1654
1660 const Val* operator->() const;
1661
1663
1664 private:
1669 friend class List< Val >;
1670
1672 ListBucket< Val >* _bucket_{nullptr};
1673
1675 ListBucket< Val >* _getBucket_() const noexcept;
1676 };
1677
1679 template < typename Val >
1680 typename ListConstIterator< Val >::difference_type
1681 operator-(const ListConstIterator< Val >& iter1, const ListConstIterator< Val >& iter2);
1682
1683 // ===========================================================================
1684 // === UNSAFE LIST ITERATORS ===
1685 // ===========================================================================
1686
1736 template < typename Val >
1737 class ListIterator: public ListConstIterator< Val > {
1738 public:
1741 using iterator_category = std::bidirectional_iterator_tag;
1742 using value_type = Val;
1743 using reference = Val&;
1744 using const_reference = const Val&;
1745 using pointer = Val*;
1746 using const_pointer = const Val*;
1747 using difference_type = std::ptrdiff_t;
1749
1750 // ============================================================================
1752 // ============================================================================
1754
1760 explicit ListIterator() noexcept;
1761
1762#ifndef DOXYGEN_SHOULD_SKIP_THIS
1763 // constructor for the static end/rend iterator
1764 // only list.cpp should use this constructor
1765 explicit consteval ListIterator(StaticInitializer init) noexcept :
1767#endif // DOXYGEN_SHOULD_SKIP_THIS
1768
1773 ListIterator(const List< Val >& theList) noexcept;
1774
1779 ListIterator(const ListIterator< Val >& src) noexcept;
1780
1785 ListIterator(ListIterator< Val >&& src) noexcept;
1786
1795 ListIterator(const List< Val >& theList, Size ind_elt);
1796
1800 ~ListIterator() noexcept;
1801
1803 // ============================================================================
1805 // ============================================================================
1807
1808 using ListConstIterator< Val >::clear;
1809 using ListConstIterator< Val >::setToEnd;
1810 using ListConstIterator< Val >::isEnd;
1811
1813
1814 // ============================================================================
1816 // ============================================================================
1818
1827 ListIterator< Val >& operator=(const ListIterator< Val >& src) noexcept;
1828
1830
1838 ListIterator< Val >& operator=(ListIterator< Val >&& src) noexcept;
1839
1854 ListIterator< Val >& operator++() noexcept;
1855
1861 ListIterator< Val >& operator+=(difference_type i) noexcept;
1862
1876 ListIterator< Val >& operator--() noexcept;
1877
1884 ListIterator< Val >& operator-=(difference_type i) noexcept;
1885
1892 ListIterator< Val > operator+(difference_type i) noexcept;
1893
1900 ListIterator< Val > operator-(difference_type i) noexcept;
1901
1911 bool operator==(const ListIterator< Val >& src) const noexcept;
1912
1922 bool operator!=(const ListIterator< Val >& src) const noexcept;
1923
1929 const Val& operator*() const;
1930
1937 Val& operator*();
1938
1944 const Val* operator->() const;
1945
1952 Val* operator->();
1953
1955 };
1956
1957 // ===========================================================================
1958 // === LIST CONST ITERATORS ===
1959 // ===========================================================================
2005 template < typename Val >
2007 public:
2010 using iterator_category = std::bidirectional_iterator_tag;
2011 using value_type = Val;
2012 using reference = Val&;
2013 using const_reference = const Val&;
2014 using pointer = Val*;
2015 using const_pointer = const Val*;
2016 using difference_type = std::ptrdiff_t;
2018
2019 // ============================================================================
2021 // ============================================================================
2023
2029 explicit ListConstIteratorSafe() noexcept;
2030
2031#ifndef DOXYGEN_SHOULD_SKIP_THIS
2032 // constructor for the static cendSafe/crendSafe iterator
2033 // only list.cpp should use this constructor
2034 explicit consteval ListConstIteratorSafe(StaticInitializer init) noexcept {}
2035#endif // DOXYGEN_SHOULD_SKIP_THIS
2036
2040 ListConstIteratorSafe(const List< Val >& theList);
2041
2047
2056 ListConstIteratorSafe(const List< Val >& theList, Size ind_elt);
2057
2063
2068
2070 // ============================================================================
2072 // ============================================================================
2074
2083 void clear();
2084
2088 void setToEnd();
2089
2096 bool isEnd() const;
2097
2099 // ============================================================================
2101 // ============================================================================
2103
2113
2121
2136
2142 ListConstIteratorSafe< Val >& operator+=(difference_type i) noexcept;
2143
2157 ListConstIteratorSafe< Val >& operator--() noexcept;
2158
2165 ListConstIteratorSafe< Val >& operator-=(difference_type i) noexcept;
2166
2173 ListConstIteratorSafe< Val > operator+(difference_type i) noexcept;
2174
2181 ListConstIteratorSafe< Val > operator-(difference_type i) noexcept;
2182
2192 bool operator!=(const ListConstIteratorSafe< Val >& src) const;
2193
2203 bool operator==(const ListConstIteratorSafe< Val >& src) const;
2204
2210 const Val& operator*() const;
2211
2217 const Val* operator->() const;
2218
2220
2221 private:
2225 friend class List< Val >;
2226 friend class ListConstIterator< Val >;
2228
2230 const List< Val >* _list_{nullptr};
2231
2234
2238
2242
2244 bool _null_pointing_{false};
2245
2247 ListBucket< Val >* _getBucket_() const noexcept;
2248
2250 void _removeFromSafeList_() const;
2251
2253 ListConstIteratorSafe< Val >& _opPlus_(Size i) noexcept;
2254
2256 ListConstIteratorSafe< Val >& _opMinus_(Size i) noexcept;
2257 };
2258
2260 template < typename Val >
2261 typename ListConstIteratorSafe< Val >::difference_type
2262 operator-(const ListConstIteratorSafe< Val >& iter1,
2263 const ListConstIteratorSafe< Val >& iter2);
2264
2265 // ===========================================================================
2266 // === LIST ITERATORS ===
2267 // ===========================================================================
2268
2318 template < typename Val >
2320 public:
2323 using iterator_category = std::bidirectional_iterator_tag;
2324 using value_type = Val;
2325 using reference = Val&;
2326 using const_reference = const Val&;
2327 using pointer = Val*;
2328 using const_pointer = const Val*;
2329 using difference_type = std::ptrdiff_t;
2331
2332 // ============================================================================
2334 // ============================================================================
2336
2342 explicit ListIteratorSafe() noexcept;
2343
2344#ifndef DOXYGEN_SHOULD_SKIP_THIS
2345 // constructor for the static endSafe/rendSafe iterator
2346 // only list.cpp should use this constructor
2347 explicit consteval ListIteratorSafe(StaticInitializer init) noexcept :
2349#endif // DOXYGEN_SHOULD_SKIP_THIS
2350
2354 ListIteratorSafe(const List< Val >& theList);
2355
2361
2370 ListIteratorSafe(const List< Val >& theList, Size ind_elt);
2371
2377
2382
2384 // ============================================================================
2386 // ============================================================================
2388
2389 using ListConstIteratorSafe< Val >::clear;
2391 using ListConstIteratorSafe< Val >::isEnd;
2392
2394 // ============================================================================
2396 // ============================================================================
2398
2408
2416
2431
2437 ListIteratorSafe< Val >& operator+=(difference_type i) noexcept;
2438
2452 ListIteratorSafe< Val >& operator--() noexcept;
2453
2460 ListIteratorSafe< Val >& operator-=(difference_type i) noexcept;
2461
2468 ListIteratorSafe< Val > operator+(difference_type i) noexcept;
2469
2476 ListIteratorSafe< Val > operator-(difference_type i) noexcept;
2477
2483 Val& operator*();
2484
2490 Val* operator->();
2491
2501 bool operator!=(const ListIteratorSafe< Val >& src) const;
2502
2512 bool operator==(const ListIteratorSafe< Val >& src) const;
2513
2519 const Val& operator*() const;
2520
2526 const Val* operator->() const;
2527 };
2528
2529#ifndef DOXYGEN_SHOULD_SKIP_THIS
2530 // _static_list_end_ is a 'constant' iterator initialized at compile time
2531 // that represents the end iterators for all lists (whatever their content).
2532 // This global variable avoids creating the same iterators within every
2533 // List instance (this would be quite inefficient as end is precisely
2534 // identical for all lists). The same holds for reverse and safe end iterators.
2535 // The type of _list_end_ is a pointer to void because C++ allows
2536 // pointers to void to be cast into pointers to other types (and conversely).
2537 // This avoids the painful strict-aliasing rule warning
2538 extern const ListConstIteratorSafe< Debug > _static_list_end_safe_;
2539 extern const ListConstIterator< Debug > _static_list_end_;
2540
2541 inline constexpr void* const _list_end_safe_ = (void* const)&_static_list_end_safe_;
2542 inline constexpr void* const _list_end_ = (void* const)&_static_list_end_;
2543#endif // DOXYGEN_SHOULD_SKIP_THIS
2544
2545} /* namespace gum */
2546
2547
2548#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
2549extern template class gum::List< bool >;
2550extern template class gum::List< int >;
2551extern template class gum::List< unsigned int >;
2552#endif
2553
2554
2555// always include the implementation of the templates
2557
2558#endif /* GUM_LIST_H */
Bucket for a chained list.
Definition list.h:114
Val _val_
Val is the value contained in the box.
Definition list.h:257
const ListBucket< Val > * next() const noexcept
Returns the bucket toward the next element.
Definition list_tpl.h:136
ListBucket< Val > * _next_
Chaining toward the adjacent elements.
Definition list.h:253
const ListBucket< Val > * previous() const noexcept
Returns the bucket toward the preceding element.
Definition list_tpl.h:142
bool operator==(const ListBucket< Val > &src) const
Equality check.
Definition list_tpl.h:112
ListBucket< Val > & operator=(const ListBucket< Val > &src)
Copy operator.
Definition list_tpl.h:93
ListBucket()=delete
Removes empty constructor.
~ListBucket()
Class destructor.
Definition list_tpl.h:105
Val & operator*() noexcept
Dereferencing operator.
Definition list_tpl.h:130
Emplace
C dummy type for the emplace constructor.
Definition list.h:121
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:252
ListBucket< Val > & operator=(ListBucket< Val > &&src)=delete
Move operator.
bool operator!=(const ListBucket< Val > &src) const
Inequality check.
Definition list_tpl.h:118
Safe const iterators for Lists.
Definition list.h:2006
Val value_type
Types for STL compliance.
Definition list.h:2011
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition list.h:2233
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:2016
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:2010
Val * pointer
Types for STL compliance.
Definition list.h:2014
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:2237
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:2241
const Val & const_reference
Types for STL compliance.
Definition list.h:2013
ListConstIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:509
const Val * const_pointer
Types for STL compliance.
Definition list.h:2015
const List< Val > * _list_
The list the iterator is pointing to.
Definition list.h:2230
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition list.h:2244
Val & reference
Types for STL compliance.
Definition list.h:2012
Unsafe but fast const iterators for Lists.
Definition list.h:1450
const Val * const_pointer
Types for STL compliance.
Definition list.h:1459
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition list.h:1672
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:1460
Val value_type
Types for STL compliance.
Definition list.h:1455
bool isEnd() const noexcept
Returns a bool indicating whether the iterator points to the end of the list.
Definition list_tpl.h:256
const Val & const_reference
Types for STL compliance.
Definition list.h:1457
ListConstIterator< Val > & operator=(const ListConstIterator< Val > &src) noexcept
Copy operator.
Definition list_tpl.h:217
ListBucket< Val > * _getBucket_() const noexcept
Returns the bucket the iterator is pointing to.
Definition list_tpl.h:237
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:1454
void clear() noexcept
Makes the iterator point toward nothing.
Definition list_tpl.h:243
~ListConstIterator() noexcept
Class Desctructor.
Definition list_tpl.h:209
ListConstIterator() noexcept
Default constructor.
Definition list_tpl.h:154
Val & reference
Types for STL compliance.
Definition list.h:1456
void setToEnd() noexcept
Positions the iterator to the end of the list.
Definition list_tpl.h:249
ListConstIterator< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
Definition list_tpl.h:262
Val * pointer
Types for STL compliance.
Definition list.h:1458
Safe iterators for Lists.
Definition list.h:2319
Val * pointer
Types for STL compliance.
Definition list.h:2327
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:2329
Val value_type
Types for STL compliance.
Definition list.h:2324
ListIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:967
const Val * const_pointer
Types for STL compliance.
Definition list.h:2328
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:2323
Val & reference
Types for STL compliance.
Definition list.h:2325
const Val & const_reference
Types for STL compliance.
Definition list.h:2326
Unsafe but fast iterators for Lists.
Definition list.h:1737
Val value_type
Types for STL compliance.
Definition list.h:1742
const Val * const_pointer
Types for STL compliance.
Definition list.h:1746
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:1747
std::bidirectional_iterator_tag iterator_category
Types for STL compliance.
Definition list.h:1741
Val & reference
Types for STL compliance.
Definition list.h:1743
ListIterator() noexcept
Default constructor.
Definition list_tpl.h:365
Val * pointer
Types for STL compliance.
Definition list.h:1745
const Val & const_reference
Types for STL compliance.
Definition list.h:1744
Generic doubly linked lists.
Definition list.h:379
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.
Definition list.h:1263
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
Definition list_tpl.h:1802
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition list_tpl.h:1793
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1354
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
Definition list_tpl.h:1386
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
Definition list_tpl.h:1725
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Definition list_tpl.h:1288
Val & front() const
Returns a reference to first element of a list, if any.
Definition list_tpl.h:1703
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition list_tpl.h:1527
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:393
std::ptrdiff_t difference_type
Types for STL compliance.
Definition list.h:389
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1390
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1312
location
Locations around iterators where insertions of new elements can take / place.
Definition list.h:398
Val & push_front(Args &&... args)
An alias for pushFront used for STL compliance.
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition list_tpl.h:1462
List()
A basic constructor that creates an empty list.
Definition list_tpl.h:1174
Val * pointer
Types for STL compliance.
Definition list.h:386
void popBack()
Removes the last element of a List, if any.
Definition list_tpl.h:1819
Size size() const noexcept
Returns the number of elements in the list.
Definition list_tpl.h:1719
void clear()
Deletes all the elements of a chained list.
Definition list_tpl.h:1154
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1391
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1392
std::string toString() const
Converts a list into a string.
Definition list_tpl.h:1837
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition list_tpl.h:1831
ListIterator< Val > iterator
Types for STL compliance.
Definition list.h:390
void eraseAllVal(const Val &val)
erases all the elements encountered with a given value
Definition list_tpl.h:1808
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1389
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
Definition list_tpl.h:1379
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
Definition list_tpl.h:1856
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition list_tpl.h:1734
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
Definition list_tpl.h:1393
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1330
Val & push_back(Args &&... args)
An alias for pushBack used for STL compliance.
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
Definition list_tpl.h:1294
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1318
void popFront()
Removes the first element of a List, if any.
Definition list_tpl.h:1825
Val & emplaceBack(Args &&... args)
Emplace elements at the end of the chained list.
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1324
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition list_tpl.h:1541
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1372
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition list.h:1254
Val value_type
Types for STL compliance.
Definition list.h:383
~List()
Class destructor.
Definition list_tpl.h:1227
const Val & const_reference
Types for STL compliance.
Definition list.h:385
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1282
Size size_type
Types for STL compliance.
Definition list.h:388
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition list_tpl.h:1559
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
Definition list.h:392
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition list_tpl.h:1300
const Val * const_pointer
Types for STL compliance.
Definition list.h:387
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
Definition list_tpl.h:1348
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition list_tpl.h:1515
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition list_tpl.h:1360
Size _nb_elements_
The number of elements in the list.
Definition list.h:1260
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1342
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
Definition list_tpl.h:1115
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1488
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition list_tpl.h:1427
Val & emplace(const const_iterator &iter, Args &&... args)
Emplace a new element before a given iterator.
Val & back() const
Returns a reference to last element of a list, if any.
Definition list_tpl.h:1711
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
Definition list_tpl.h:1772
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition list_tpl.h:1444
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:1596
void swap(List &other_list)
Swap the current list with another one.
Definition list_tpl.h:1966
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition list.h:391
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition list_tpl.h:1407
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition list.h:1257
Val & reference
Types for STL compliance.
Definition list.h:384
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
Definition AVLTree.h:913
STL namespace.
Class providing aGrUM's "smart" pointers.
Data types to enable creating static variables at compile time.