Embedded Template Library 1.0
Loading...
Searching...
No Matches
forward_list.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2014 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_FORWARD_LIST_INCLUDED
32#define ETL_FORWARD_LIST_INCLUDED
33
34#include "platform.h"
35#include "algorithm.h"
36#include "iterator.h"
37#include "functional.h"
38#include "utility.h"
39#include "pool.h"
40#include "exception.h"
41#include "error_handler.h"
42#include "debug_count.h"
43#include "nullptr.h"
44#include "type_traits.h"
45#include "memory.h"
46#include "iterator.h"
47#include "static_assert.h"
48#include "placement_new.h"
49#include "initializer_list.h"
50
51#include <stddef.h>
52
53#include "private/minmax_push.h"
54
55//*****************************************************************************
59//*****************************************************************************
60
61namespace etl
62{
63 //***************************************************************************
66 //***************************************************************************
76
77 //***************************************************************************
80 //***************************************************************************
82 {
83 public:
84
86 : etl::forward_list_exception(ETL_ERROR_TEXT("forward_list:full", ETL_FORWARD_LIST_FILE_ID"A"), file_name_, line_number_)
87 {
88 }
89 };
90
91 //***************************************************************************
94 //***************************************************************************
96 {
97 public:
98
100 : etl::forward_list_exception(ETL_ERROR_TEXT("forward_list:empty", ETL_FORWARD_LIST_FILE_ID"B"), file_name_, line_number_)
101 {
102 }
103 };
104
105 //***************************************************************************
108 //***************************************************************************
110 {
111 public:
112
114 : etl::forward_list_exception(ETL_ERROR_TEXT("forward_list:iterator", ETL_FORWARD_LIST_FILE_ID"C"), file_name_, line_number_)
115 {
116 }
117 };
118
119 //***************************************************************************
122 //***************************************************************************
124 {
125 public:
126
128 : forward_list_exception(ETL_ERROR_TEXT("list:no pool", ETL_FORWARD_LIST_FILE_ID"D"), file_name_, line_number_)
129 {
130 }
131 };
132
133 //***************************************************************************
136 //***************************************************************************
138 {
139 protected:
140
141 //*************************************************************************
143 //*************************************************************************
144 struct node_t
145 {
146 node_t()
147 : next(ETL_NULLPTR)
148 {
149 }
150
151 node_t* next;
152 };
153
154 public:
155
156 typedef size_t size_type;
157
158 //*************************************************************************
160 //*************************************************************************
161 bool has_shared_pool() const
162 {
163 return pool_is_shared;
164 }
165
166 //*************************************************************************
168 //*************************************************************************
170 {
171 return MAX_SIZE;
172 }
173
174 //*************************************************************************
176 //*************************************************************************
178 {
179 return MAX_SIZE;
180 }
181
182 //*************************************************************************
184 //*************************************************************************
186 {
187 if (has_shared_pool())
188 {
189 // We have to count what we actually own.
190 size_type count = 0;
191
192 node_t* p_node = start_node.next;
193
194 while (p_node != ETL_NULLPTR)
195 {
196 ++count;
197 p_node = p_node->next;
198 }
199
200 return count;
201 }
202 else
203 {
204 return p_node_pool->size();
205 }
206 }
207
208 //*************************************************************************
210 //*************************************************************************
211 bool empty() const
212 {
213 return (start_node.next == ETL_NULLPTR);
214 }
215
216 //*************************************************************************
218 //*************************************************************************
219 bool full() const
220 {
221 ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool));
222 return p_node_pool->full();
223 }
224
225 //*************************************************************************
228 //*************************************************************************
229 size_t available() const
230 {
231 ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool));
232 return p_node_pool->available();
233 }
234
235 //*************************************************************************
237 //*************************************************************************
238 void reverse()
239 {
240 if (is_trivial_list())
241 {
242 return;
243 }
244
246 node_t* p_current = p_last->next;
247 node_t* p_next = p_current->next;
248
249 p_current->next = ETL_NULLPTR;
250
251 while (p_next != ETL_NULLPTR)
252 {
254 p_current = p_next;
255 p_next = p_current->next;
256
257 p_current->next = p_last;
258 }
259
261 }
262
263 protected:
264
265 //*************************************************************************
267 //*************************************************************************
269 : p_node_pool(ETL_NULLPTR),
270 MAX_SIZE(0),
272 {
273 }
274
275 //*************************************************************************
277 //*************************************************************************
284
285 //*************************************************************************
287 //*************************************************************************
289 {
290 }
291
292 //*************************************************************************
294 //*************************************************************************
296 {
297 return start_node.next;
298 }
299
300 //*************************************************************************
302 //*************************************************************************
303 const node_t* get_head() const
304 {
305 return start_node.next;
306 }
307
308 //*************************************************************************
310 //*************************************************************************
311 inline void insert_node_after(node_t& position, node_t& node)
312 {
313 // Connect to the forward_list.
314 join(&node, position.next);
315 join(&position, &node);
316 }
317
318 //*************************************************************************
320 //*************************************************************************
321 bool is_trivial_list() const
322 {
323 return (size() < 2);
324 }
325
326 //*************************************************************************
328 //*************************************************************************
329 void join(node_t* left, node_t* right)
330 {
331 left->next = right;
332 }
333
334 //*************************************************************************
336 //*************************************************************************
342
343 //*************************************************************************
345 //*************************************************************************
347 {
348 return p_node_pool;
349 }
350
356 };
357
358 //***************************************************************************
361 //***************************************************************************
362 template <typename T>
364 {
365 public:
366
367 typedef T value_type;
368 typedef T* pointer;
369 typedef const T* const_pointer;
370 typedef T& reference;
371 typedef const T& const_reference;
372 typedef size_t size_type;
373
374#if ETL_USING_CPP11
375 typedef T&& rvalue_reference;
376#endif
377
378 protected:
379
380 //*************************************************************************
382 //*************************************************************************
383 struct data_node_t : public node_t
384 {
385 explicit data_node_t(const T& value_)
386 : value(value_)
387 {}
388
389 T value;
390 };
391
392 public:
393
394 //*************************************************************************
396 //*************************************************************************
397 class iterator : public etl::iterator<ETL_OR_STD::forward_iterator_tag, T>
398 {
399 public:
400
401 friend class iforward_list;
402 friend class const_iterator;
403
404 iterator()
405 : p_node(ETL_NULLPTR)
406 {
407 }
408
410 : p_node(node)
411 {
412 }
413
414 iterator(const iterator& other)
415 : p_node(other.p_node)
416 {
417 }
418
420 {
421 p_node = p_node->next;
422 return *this;
423 }
424
426 {
427 iterator temp(*this);
428 p_node = p_node->next;
429 return temp;
430 }
431
433 {
434 p_node = other.p_node;
435 return *this;
436 }
437
438 reference operator *() const
439 {
440 return iforward_list::data_cast(p_node)->value;
441 }
442
443 pointer operator &() const
444 {
445 return &(iforward_list::data_cast(p_node)->value);
446 }
447
448 pointer operator ->() const
449 {
450 return &(iforward_list::data_cast(p_node)->value);
451 }
452
453 friend bool operator == (const iterator& lhs, const iterator& rhs)
454 {
455 return lhs.p_node == rhs.p_node;
456 }
457
458 friend bool operator != (const iterator& lhs, const iterator& rhs)
459 {
460 return !(lhs == rhs);
461 }
462
463 private:
464
465 node_t* p_node;
466 };
467
468 //*************************************************************************
470 //*************************************************************************
471 class const_iterator : public etl::iterator<ETL_OR_STD::forward_iterator_tag, const T>
472 {
473 public:
474
475 friend class iforward_list;
476
478 : p_node(ETL_NULLPTR)
479 {
480 }
481
483 : p_node(node)
484 {
485 }
486
488 : p_node(node)
489 {
490 }
491
493 : p_node(other.p_node)
494 {
495 }
496
498 : p_node(other.p_node)
499 {
500 }
501
503 {
504 p_node = p_node->next;
505 return *this;
506 }
507
509 {
510 const_iterator temp(*this);
511 p_node = p_node->next;
512 return temp;
513 }
514
516 {
517 p_node = other.p_node;
518 return *this;
519 }
520
522 {
523 return iforward_list::data_cast(p_node)->value;
524 }
525
527 {
528 return &(iforward_list::data_cast(p_node)->value);
529 }
530
532 {
533 return &(iforward_list::data_cast(p_node)->value);
534 }
535
536 friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
537 {
538 return lhs.p_node == rhs.p_node;
539 }
540
541 friend bool operator != (const const_iterator& lhs, const const_iterator& rhs)
542 {
543 return !(lhs == rhs);
544 }
545
546 private:
547
548 const node_t* p_node;
549 };
550
551 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
552
553 //*************************************************************************
555 //*************************************************************************
557 {
558 return iterator(get_head());
559 }
560
561 //*************************************************************************
563 //*************************************************************************
565 {
566 return const_iterator(get_head());
567 }
568
569 //*************************************************************************
571 //*************************************************************************
573 {
574 return iterator(&start_node);
575 }
576
577 //*************************************************************************
579 //*************************************************************************
581 {
582 return const_iterator(&start_node);
583 }
584
585 //*************************************************************************
587 //*************************************************************************
589 {
590 return const_iterator(get_head());
591 }
592
593 //*************************************************************************
595 //*************************************************************************
597 {
598 return iterator();
599 }
600
601 //*************************************************************************
603 //*************************************************************************
605 {
606 return const_iterator();
607 }
608
609 //*************************************************************************
611 //*************************************************************************
613 {
614 return const_iterator();
615 }
616
617 //*************************************************************************
619 //*************************************************************************
620 void clear()
621 {
622 initialise();
623 }
624
625 //*************************************************************************
627 //*************************************************************************
629 {
630 return data_cast(*get_head()).value;
631 }
632
633 //*************************************************************************
635 //*************************************************************************
637 {
638 return data_cast(*get_head()).value;
639 }
640
641 //*************************************************************************
645 //*************************************************************************
646 template <typename TIterator>
648 {
649#if ETL_IS_DEBUG_BUILD
650 difference_type d = etl::distance(first, last);
651 ETL_ASSERT(d >= 0, ETL_ERROR(forward_list_iterator));
652#endif
653
654 initialise();
655
657
658 // Add all of the elements.
659 while (first != last)
660 {
661 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
662
664 ++first;
666 data_node.next = ETL_NULLPTR;
668 }
669 }
670
671 //*************************************************************************
673 //*************************************************************************
674 void assign(size_t n, const T& value)
675 {
676 ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full));
677
678 initialise();
679
681
682 // Add all of the elements.
683 while (size() < n)
684 {
687 data_node.next = ETL_NULLPTR;
689 }
690 }
691
692 //*************************************************************************
694 //*************************************************************************
695 void push_front(const T& value)
696 {
697#if defined(ETL_CHECK_PUSH_POP)
698 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
699#endif
700
703 }
704
705#if ETL_USING_CPP11
706 //*************************************************************************
708 //*************************************************************************
709 void push_front(rvalue_reference value)
710 {
711#if defined(ETL_CHECK_PUSH_POP)
712 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
713#endif
714
715 data_node_t& data_node = allocate_data_node(etl::move(value));
717 }
718#endif
719
720#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
721 //*************************************************************************
723 //*************************************************************************
724 template <typename ... Args>
725 reference emplace_front(Args && ... args)
726 {
727#if defined(ETL_CHECK_PUSH_POP)
728 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
729#endif
730 data_node_t* p_data_node = allocate_data_node();
731 ::new (&(p_data_node->value)) T(etl::forward<Args>(args)...);
732 ETL_INCREMENT_DEBUG_COUNT;
733 insert_node_after(start_node, *p_data_node);
734 return front();
735 }
736#else
737 //*************************************************************************
739 //*************************************************************************
741 {
742#if defined(ETL_CHECK_PUSH_POP)
743 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
744#endif
746 ::new (&(p_data_node->value)) T();
747 ETL_INCREMENT_DEBUG_COUNT;
749 return front();
750 }
751
752 //*************************************************************************
754 //*************************************************************************
755 template <typename T1>
757 {
758#if defined(ETL_CHECK_PUSH_POP)
759 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
760#endif
762 ::new (&(p_data_node->value)) T(value1);
763 ETL_INCREMENT_DEBUG_COUNT;
765 return front();
766 }
767
768 //*************************************************************************
770 //*************************************************************************
771 template <typename T1, typename T2>
772 reference emplace_front(const T1& value1, const T2& value2)
773 {
774#if defined(ETL_CHECK_PUSH_POP)
775 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
776#endif
778 ::new (&(p_data_node->value)) T(value1, value2);
779 ETL_INCREMENT_DEBUG_COUNT;
781 return front();
782 }
783
784 //*************************************************************************
786 //*************************************************************************
787 template <typename T1, typename T2, typename T3>
788 reference emplace_front(const T1& value1, const T2& value2, const T3& value3)
789 {
790#if defined(ETL_CHECK_PUSH_POP)
791 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
792#endif
794 ::new (&(p_data_node->value)) T(value1, value2, value3);
795 ETL_INCREMENT_DEBUG_COUNT;
797 return front();
798 }
799
800 //*************************************************************************
802 //*************************************************************************
803 template <typename T1, typename T2, typename T3, typename T4>
804 reference emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
805 {
806#if defined(ETL_CHECK_PUSH_POP)
807 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
808#endif
810 ::new (&(p_data_node->value)) T(value1, value2, value3, value4);
811 ETL_INCREMENT_DEBUG_COUNT;
813 return front();
814 }
815#endif // ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
816
817 //*************************************************************************
819 //*************************************************************************
821 {
822#if defined(ETL_CHECK_PUSH_POP)
823 ETL_ASSERT(!empty(), ETL_ERROR(forward_list_empty));
824#endif
825 remove_node_after(start_node);
826 }
827
828 //*************************************************************************
830 //*************************************************************************
831 void resize(size_t n)
832 {
833 resize(n, T());
834 }
835
836 //*************************************************************************
840 //*************************************************************************
841 void resize(size_t n, T value)
842 {
843 ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full));
844
845 if (n == 0U)
846 {
847 clear();
848 }
849 else if (empty())
850 {
851 assign(n, value);
852 }
853 else
854 {
855 size_t i = 0UL;
858
859 // Find where we're currently at.
860 while ((i < n) && (i_node != end()))
861 {
862 ++i;
864 ++i_node;
865 }
866
867 if (i_node != end())
868 {
869 // Reduce.
871 }
872 else if (i_node == end())
873 {
874 // Increase.
875 while (i < n)
876 {
878 ++i;
879 }
880 }
881 }
882 }
883
884 //*************************************************************************
886 //*************************************************************************
887 iterator insert_after(const_iterator position, const T& value)
888 {
889 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
890
892 insert_node_after(*to_iterator(position).p_node, data_node);
893
894 return iterator(&data_node);
895 }
896
897#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
898 //*************************************************************************
900 //*************************************************************************
901 template <typename ... Args>
902 iterator emplace_after(const_iterator position, Args && ... args)
903 {
904 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
905
906 data_node_t* p_data_node = allocate_data_node();
907 ::new (&(p_data_node->value)) T(etl::forward<Args>(args)...);
908 ETL_INCREMENT_DEBUG_COUNT;
909 insert_node_after(*to_iterator(position).p_node, *p_data_node);
910
912 }
913#else
914 //*************************************************************************
916 //*************************************************************************
918 {
919 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
920
922 ::new (&(p_data_node->value)) T();
923 ETL_INCREMENT_DEBUG_COUNT;
924 insert_node_after(*to_iterator(position).p_node, *p_data_node);
925
926 return iterator(p_data_node);
927 }
928
929 //*************************************************************************
931 //*************************************************************************
932 template <typename T1>
933 iterator emplace_after(const_iterator position, const T1& value1)
934 {
935 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
936
938 ::new (&(p_data_node->value)) T(value1);
939 ETL_INCREMENT_DEBUG_COUNT;
940 insert_node_after(*to_iterator(position).p_node, *p_data_node);
941
942 return iterator(p_data_node);
943 }
944
945 //*************************************************************************
947 //*************************************************************************
948 template <typename T1, typename T2>
949 iterator emplace_after(const_iterator position, const T1& value1, const T2& value2)
950 {
951 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
952
954 ::new (&(p_data_node->value)) T(value1, value2);
955 ETL_INCREMENT_DEBUG_COUNT;
956 insert_node_after(*to_iterator(position).p_node, *p_data_node);
957
958 return iterator(p_data_node);
959 }
960
961 //*************************************************************************
963 //*************************************************************************
964 template <typename T1, typename T2, typename T3>
965 iterator emplace_after(const_iterator position, const T1& value1, const T2& value2, const T3& value3)
966 {
967 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
968
970 ::new (&(p_data_node->value)) T(value1, value2, value3);
971 ETL_INCREMENT_DEBUG_COUNT;
972 insert_node_after(*to_iterator(position).p_node, *p_data_node);
973
974 return iterator(p_data_node);
975 }
976
977 //*************************************************************************
979 //*************************************************************************
980 template <typename T1, typename T2, typename T3, typename T4>
981 iterator emplace_after(const_iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
982 {
983 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
984
986 ::new (&(p_data_node->value)) T(value1, value2, value3, value4);
987 ETL_INCREMENT_DEBUG_COUNT;
988 insert_node_after(*to_iterator(position).p_node, *p_data_node);
989
990 return iterator(p_data_node);
991 }
992#endif // ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
993
994 //*************************************************************************
996 //*************************************************************************
997 iterator insert_after(const_iterator position, size_t n, const T& value)
998 {
999 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
1000
1001 for (size_t i = 0UL; !full() && (i < n); ++i)
1002 {
1003 // Set up the next free node.
1005 insert_node_after(*to_iterator(position).p_node, data_node);
1006 }
1007
1008 if (n > 0U)
1009 {
1010 ++position;
1011 }
1012
1013 return to_iterator(position);
1014 }
1015
1016 //*************************************************************************
1018 //*************************************************************************
1019 template <typename TIterator>
1021 {
1022#if ETL_IS_DEBUG_BUILD
1023 difference_type d = etl::distance(first, last);
1024 ETL_ASSERT((d + size()) <= MAX_SIZE, ETL_ERROR(forward_list_full));
1025#endif
1026
1027 while (first != last)
1028 {
1029 // Set up the next free node.
1031 ++first;
1032 insert_node_after(*to_iterator(position).p_node, data_node);
1033 ++position;
1034 }
1035
1036 return to_iterator(position);
1037 }
1038
1039 //*************************************************************************
1041 //*************************************************************************
1043 {
1044 iterator next(position);
1045 if (next != end())
1046 {
1047 ++next;
1048 if (next != end())
1049 {
1050 ++next;
1051 remove_node_after(*position.p_node);
1052 }
1053 }
1054
1055 return next;
1056 }
1057
1058 //*************************************************************************
1060 //*************************************************************************
1062 {
1063 iterator next(position);
1064 if (next != end())
1065 {
1066 ++next;
1067 if (next != end())
1068 {
1069 ++next;
1070 remove_node_after(*position.p_node);
1071 }
1072 }
1073
1074 return next;
1075 }
1076
1077 //*************************************************************************
1079 //*************************************************************************
1081 {
1082 if (first != end() && (first != last))
1083 {
1084 node_t* p_first = to_iterator(first).p_node;
1085 node_t* p_last = to_iterator(last).p_node;
1086 node_t* p_next = p_first->next;
1087
1088 // Join the ends.
1090
1091 p_first = p_next;
1092
1093 // Erase the ones in between.
1094 while (p_first != p_last)
1095 {
1096 p_next = p_first->next; // Remember the next node.
1097 destroy_data_node(static_cast<data_node_t&>(*p_first)); // Destroy the pool object.
1098 p_first = p_next; // Move to the next node.
1099 }
1100
1101 if (p_next == ETL_NULLPTR)
1102 {
1103 return end();
1104 }
1105 else
1106 {
1107 return iterator(p_last);
1108 }
1109 }
1110 else
1111 {
1112 return end();
1113 }
1114 }
1115
1116 //*************************************************************************
1119 //*************************************************************************
1121 {
1122 if (from_before == to_before) // Can't move to after yourself!
1123 {
1124 return;
1125 }
1126
1127 node_t* p_from_before = const_cast<node_t*>(from_before.p_node); // We're not changing the value, just it's position.
1128 node_t* p_to_before = const_cast<node_t*>(to_before.p_node); // We're not changing the value, just it's position.
1129
1130 node_t* p_from = p_from_before->next;
1131
1132 // Disconnect from the list.
1133 join(p_from_before, p_from->next);
1134
1135 // Attach it to the new position.
1136 join(p_from, p_to_before->next);
1138 }
1139
1140 //*************************************************************************
1143 //*************************************************************************
1145 {
1146 if ((first_before == to_before) || (last == to_before))
1147 {
1148 return; // Can't more to before yourself!
1149 }
1150
1151//#if ETL_IS_DEBUG_BUILD
1152 // Check that we are not doing an illegal move!
1153 for (const_iterator item = first_before; item != last; ++item)
1154 {
1156 }
1157//#endif
1158
1159 node_t* p_first_before = const_cast<node_t*>(first_before.p_node); // We're not changing the value, just it's position.
1160 node_t* p_last = const_cast<node_t*>(last.p_node); // We're not changing the value, just it's position.
1161 node_t* p_to_before = const_cast<node_t*>(to_before.p_node); // We're not changing the value, just it's position.
1162 node_t* p_first = p_first_before->next;
1164
1165 // Find the last node that will be moved.
1166 while (p_final->next != p_last)
1167 {
1168 p_final = p_final->next;
1169 }
1170
1171 // Disconnect from the list.
1172 join(p_first_before, p_final->next);
1173
1174 // Attach it to the new position.
1175 join(p_final, p_to_before->next);
1177 }
1178
1179 //*************************************************************************
1182 //*************************************************************************
1183 void unique()
1184 {
1186 }
1187
1188 //*************************************************************************
1191 //*************************************************************************
1192 template <typename TIsEqual>
1194 {
1195 if (empty())
1196 {
1197 return;
1198 }
1199
1200 node_t* last = get_head();
1201 node_t* current = last->next;
1202
1203 while (current != ETL_NULLPTR)
1204 {
1205 // Is this value the same as the last?
1206 if (isEqual(data_cast(current)->value, data_cast(last)->value))
1207 {
1208 remove_node_after(*last);
1209 }
1210 else
1211 {
1212 // Move on one.
1213 last = current;
1214 }
1215
1216 current = last->next;
1217 }
1218 }
1219
1220 //*************************************************************************
1223 //*************************************************************************
1224 void sort()
1225 {
1226 sort(etl::less<T>());
1227 }
1228
1229 //*************************************************************************
1253 //*************************************************************************
1254 template <typename TCompare>
1256 {
1259 iterator p_node;
1262 int list_size = 1;
1263 int number_of_merges;
1264 int left_size;
1265 int right_size;
1266
1267 if (is_trivial_list())
1268 {
1269 return;
1270 }
1271
1272 while (true)
1273 {
1274 p_left = begin();
1275 p_head = before_begin();
1276 p_tail = before_begin();
1277
1278 number_of_merges = 0; // Count the number of merges we do in this pass.
1279
1280 while (p_left != end())
1281 {
1282 ++number_of_merges; // There exists a merge to be done.
1283 p_right = p_left;
1284 left_size = 0;
1285
1286 // Step 'list_size' places along from left
1287 for (int i = 0; i < list_size; ++i)
1288 {
1289 ++left_size;
1290
1291 ++p_right;
1292
1293 if (p_right == end())
1294 {
1295 break;
1296 }
1297 }
1298
1299 // If right hasn't fallen off end, we have two lists to merge.
1301
1302 // Now we have two lists. Merge them.
1303 while (left_size > 0 || (right_size > 0 && p_right != end()))
1304 {
1305 // Decide whether the next node of merge comes from left or right.
1306 if (left_size == 0)
1307 {
1308 // Left is empty. The node must come from right.
1309 p_node = p_right;
1310 ++p_right;
1311 --right_size;
1312 }
1313 else if (right_size == 0 || p_right == end())
1314 {
1315 // Right is empty. The node must come from left.
1316 p_node = p_left;
1317 ++p_left;
1318 --left_size;
1319 }
1320 else if (!compare(*p_right, *p_left))
1321 {
1322 // First node of left is lower or same. The node must come from left.
1323 p_node = p_left;
1324 ++p_left;
1325 --left_size;
1326 }
1327 else
1328 {
1329 // First node of right is lower. The node must come from right.
1330 p_node = p_right;
1331 ++p_right;
1332 --right_size;
1333 }
1334
1335 // Add the next node to the merged head.
1336 if (p_head == before_begin())
1337 {
1338 join(p_head.p_node, p_node.p_node);
1339 p_head = p_node;
1340 p_tail = p_node;
1341 }
1342 else
1343 {
1344 join(p_tail.p_node, p_node.p_node);
1345 p_tail = p_node;
1346 }
1347
1348 p_tail.p_node->next = ETL_NULLPTR;
1349 }
1350
1351 // Now left has stepped `list_size' places along, and right has too.
1352 p_left = p_right;
1353 }
1354
1355 // If we have done only one merge, we're finished.
1356 if (number_of_merges <= 1) // Allow for number_of_merges == 0, the empty head case
1357 {
1358 return;
1359 }
1360
1361 // Otherwise repeat, merging lists twice the size
1362 list_size *= 2;
1363 }
1364 }
1365
1366 //*************************************************************************
1367 // Removes the values specified.
1368 //*************************************************************************
1369 void remove(const T& value)
1370 {
1371 iterator i_item = begin();
1373
1374 while (i_item != end())
1375 {
1376 if (*i_item == value)
1377 {
1379 }
1380 else
1381 {
1382 ++i_item;
1383 ++i_last_item;
1384 }
1385 }
1386 }
1387
1388 //*************************************************************************
1390 //*************************************************************************
1391 template <typename TPredicate>
1393 {
1394 iterator i_item = begin();
1396
1397 while (i_item != end())
1398 {
1399 if (predicate(*i_item))
1400 {
1402 }
1403 else
1404 {
1405 ++i_item;
1406 ++i_last_item;
1407 }
1408 }
1409 }
1410
1411 //*************************************************************************
1413 //*************************************************************************
1415 {
1416 if (&rhs != this)
1417 {
1418 assign(rhs.cbegin(), rhs.cend());
1419 }
1420
1421 return *this;
1422 }
1423
1424#if ETL_USING_CPP11
1425 //*************************************************************************
1427 //*************************************************************************
1429 {
1430 move_container(etl::move(rhs));
1431
1432 return *this;
1433 }
1434#endif
1435
1436 protected:
1437
1438 //*************************************************************************
1440 //*************************************************************************
1445
1446 //*************************************************************************
1448 //*************************************************************************
1451 {
1452 }
1453
1454 //*************************************************************************
1456 //*************************************************************************
1458 {
1459 if (!empty())
1460 {
1462 {
1463 ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool));
1465 ETL_RESET_DEBUG_COUNT;
1466 }
1467 else
1468 {
1469 node_t* p_first = start_node.next;
1470 node_t* p_next;
1471
1472 // Erase the ones in between.
1473 while (p_first != ETL_NULLPTR)
1474 {
1475 p_next = p_first->next; // Remember the next node.
1476 destroy_data_node(static_cast<data_node_t&>(*p_first)); // Destroy the pool object.
1477 p_first = p_next; // Move to the next node.
1478 }
1479 }
1480 }
1481
1482 start_node.next = ETL_NULLPTR;
1483 }
1484
1485 //*************************************************************************
1487 //*************************************************************************
1489 {
1490 data_node_t* p_node = allocate_data_node();
1491 ::new (&(p_node->value)) T(value);
1492 ETL_INCREMENT_DEBUG_COUNT;
1493
1494 return *p_node;
1495 }
1496
1497#if ETL_USING_CPP11
1498 //*************************************************************************
1500 //*************************************************************************
1501 data_node_t& allocate_data_node(rvalue_reference value)
1502 {
1503 data_node_t* p_node = allocate_data_node();
1504 ::new (&(p_node->value)) T(etl::move(value));
1505 ETL_INCREMENT_DEBUG_COUNT;
1506
1507 return *p_node;
1508 }
1509#endif
1510
1511#if ETL_USING_CPP11
1512 //*************************************************************************
1514 //*************************************************************************
1516 {
1517 if (&rhs != this)
1518 {
1519 this->initialise();
1520
1521 if (!rhs.empty())
1522 {
1523 // Are we using the same pool?
1524 if (this->get_node_pool() == rhs.get_node_pool())
1525 {
1526 // Just link the nodes to this list.
1527 this->start_node.next = rhs.start_node.next;
1528
1529 ETL_SET_DEBUG_COUNT(ETL_OBJECT_GET_DEBUG_COUNT(rhs));
1530
1531 ETL_OBJECT_RESET_DEBUG_COUNT(rhs);
1532 rhs.start_node.next = ETL_NULLPTR;
1533 }
1534 else
1535 {
1536 node_t* p_last_node = &this->start_node;
1537
1538 // Add all of the elements.
1539 etl::iforward_list<T>::iterator first = rhs.begin();
1540 etl::iforward_list<T>::iterator last = rhs.end();
1541
1542 while (first != last)
1543 {
1544 ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
1545
1546 data_node_t& data_node = this->allocate_data_node(etl::move(*first));
1547 ++first;
1548 join(p_last_node, &data_node);
1549 data_node.next = ETL_NULLPTR;
1550 p_last_node = &data_node;
1551 }
1552
1553 rhs.initialise();
1554 }
1555 }
1556 }
1557 }
1558#endif
1559
1560 private:
1561
1562 //*************************************************************************
1564 //*************************************************************************
1565 static data_node_t* data_cast(node_t* p_node)
1566 {
1567 return static_cast<data_node_t*>(p_node);
1568 }
1569
1570 //*************************************************************************
1572 //*************************************************************************
1573 static data_node_t& data_cast(node_t& node)
1574 {
1575 return static_cast<data_node_t&>(node);
1576 }
1577
1578 //*************************************************************************
1580 //*************************************************************************
1581 static const data_node_t* data_cast(const node_t* p_node)
1582 {
1583 return static_cast<const data_node_t*>(p_node);
1584 }
1585
1586 //*************************************************************************
1588 //*************************************************************************
1589 static const data_node_t& data_cast(const node_t& node)
1590 {
1591 return static_cast<const data_node_t&>(node);
1592 }
1593
1594 //*************************************************************************
1596 //*************************************************************************
1597 void remove_node_after(node_t& node)
1598 {
1599 // The node to erase.
1600 node_t* p_node = node.next;
1601
1602 if (p_node != ETL_NULLPTR)
1603 {
1604 // Disconnect the node from the forward_list.
1605 join(&node, p_node->next);
1606
1607 // Destroy the pool object.
1608 destroy_data_node(static_cast<data_node_t&>(*p_node));
1609 }
1610 }
1611
1612 //*************************************************************************
1614 //*************************************************************************
1615 data_node_t* allocate_data_node()
1616 {
1617 data_node_t* (etl::ipool::*func)() = &etl::ipool::allocate<data_node_t>;
1618 return (p_node_pool->*func)();
1619 }
1620
1621 //*************************************************************************
1623 //*************************************************************************
1624 void destroy_data_node(data_node_t& node)
1625 {
1626 node.value.~T();
1627 p_node_pool->release(&node);
1628 ETL_DECREMENT_DEBUG_COUNT;
1629 }
1630
1631 // Disable copy construction.
1632 iforward_list(const iforward_list&);
1633
1634 //*************************************************************************
1636 //*************************************************************************
1637#if defined(ETL_POLYMORPHIC_FORWARD_LIST) || defined(ETL_POLYMORPHIC_CONTAINERS)
1638 public:
1639 virtual ~iforward_list()
1640 {
1641 }
1642#else
1643 protected:
1645 {
1646 }
1647#endif
1648
1649 private:
1650
1651 //*************************************************************************
1653 //*************************************************************************
1654 iterator to_iterator(const_iterator itr) const
1655 {
1656 return iterator(const_cast<node_t*>(itr.p_node));
1657 }
1658 };
1659
1660 //*************************************************************************
1663 //*************************************************************************
1664 template <typename T, const size_t MAX_SIZE_>
1666 {
1667 public:
1668
1669 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::forward_list is not valid");
1670
1671 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1672
1673 public:
1674
1675 typedef T value_type;
1676 typedef T* pointer;
1677 typedef const T* const_pointer;
1678 typedef T& reference;
1679 typedef const T& const_reference;
1680 typedef size_t size_type;
1681
1682 //*************************************************************************
1684 //*************************************************************************
1686 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1687 {
1688 this->initialise();
1689 }
1690
1691 //*************************************************************************
1693 //*************************************************************************
1694 explicit forward_list(size_t initial_size, const T& value = T())
1695 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1696 {
1697 this->assign(initial_size, value);
1698 }
1699
1700 //*************************************************************************
1702 //*************************************************************************
1704 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1705 {
1706 this->assign(other.cbegin(), other.cend());
1707 }
1708
1709#if ETL_USING_CPP11
1710 //*************************************************************************
1712 //*************************************************************************
1714 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1715 {
1716 this->move_container(etl::move(other));
1717 }
1718#endif
1719
1720 //*************************************************************************
1722 //*************************************************************************
1723 template <typename TIterator>
1725 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1726 {
1727 this->assign(first, last);
1728 }
1729
1730#if ETL_HAS_INITIALIZER_LIST
1731 //*************************************************************************
1733 //*************************************************************************
1734 forward_list(std::initializer_list<T> init)
1735 : etl::iforward_list<T>(node_pool, MAX_SIZE, false)
1736 {
1737 this->assign(init.begin(), init.end());
1738 }
1739#endif
1740
1741 //*************************************************************************
1743 //*************************************************************************
1745 {
1746 this->initialise();
1747 }
1748
1749 //*************************************************************************
1751 //*************************************************************************
1753 {
1754 if (&rhs != this)
1755 {
1756 this->assign(rhs.cbegin(), rhs.cend());
1757 }
1758
1759 return *this;
1760 }
1761
1762#if ETL_USING_CPP11
1763 //*************************************************************************
1765 //*************************************************************************
1767 {
1768
1769 this->move_container(etl::move(rhs));
1770
1771 return *this;
1772 }
1773#endif
1774
1775 private:
1776
1779 };
1780
1781 template <typename T, const size_t MAX_SIZE_>
1782 ETL_CONSTANT size_t forward_list<T, MAX_SIZE_>::MAX_SIZE;
1783
1784 //*************************************************************************
1786 //*************************************************************************
1787#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1788 template <typename... T>
1789 forward_list(T...) ->forward_list<typename etl::common_type_t<T...>, sizeof...(T)>;
1790#endif
1791
1792 //*************************************************************************
1794 //*************************************************************************
1795#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1796 template <typename... T>
1797 constexpr auto make_forward_list(T&&... t) -> etl::forward_list<typename etl::common_type_t<T...>, sizeof...(T)>
1798 {
1799 return { etl::forward<T>(t)... };
1800 }
1801#endif
1802
1803 //*************************************************************************
1806 //*************************************************************************
1807 template <typename T>
1809 {
1810 public:
1811
1812 typedef T value_type;
1813 typedef T* pointer;
1814 typedef const T* const_pointer;
1815 typedef T& reference;
1816 typedef const T& const_reference;
1817 typedef size_t size_type;
1818
1820
1821 //*************************************************************************
1823 //*************************************************************************
1825 : etl::iforward_list<T>(true)
1826 {
1827 }
1828
1829 //*************************************************************************
1831 //*************************************************************************
1832 explicit forward_list_ext(etl::ipool& node_pool)
1833 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1834 {
1835 this->initialise();
1836 }
1837
1838 //*************************************************************************
1840 //*************************************************************************
1841 explicit forward_list_ext(size_t initial_size, etl::ipool& node_pool)
1842 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1843 {
1844 this->assign(initial_size, T());
1845 }
1846
1847 //*************************************************************************
1849 //*************************************************************************
1850 explicit forward_list_ext(size_t initial_size, const T& value, etl::ipool& node_pool)
1851 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1852 {
1853 this->assign(initial_size, value);
1854 }
1855
1856 //*************************************************************************
1858 //*************************************************************************
1860 : etl::iforward_list<T>(*other.p_node_pool, other.p_node_pool->max_size(), true)
1861 {
1862 this->assign(other.cbegin(), other.cend());
1863 }
1864
1865 //*************************************************************************
1867 //*************************************************************************
1869 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1870 {
1871 this->assign(other.cbegin(), other.cend());
1872 }
1873
1874#if ETL_USING_CPP11
1875 //*************************************************************************
1877 //*************************************************************************
1879 : etl::iforward_list<T>(*other.p_node_pool, other.p_node_pool->max_size(), true)
1880 {
1881 this->move_container(etl::move(other));
1882 }
1883
1884 //*************************************************************************
1886 //*************************************************************************
1887 forward_list_ext(forward_list_ext&& other, etl::ipool& node_pool)
1888 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1889 {
1890 this->move_container(etl::move(other));
1891 }
1892#endif
1893
1894 //*************************************************************************
1896 //*************************************************************************
1897 template <typename TIterator>
1899 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1900 {
1901 this->assign(first, last);
1902 }
1903
1904#if ETL_HAS_INITIALIZER_LIST
1905 //*************************************************************************
1907 //*************************************************************************
1908 forward_list_ext(std::initializer_list<T> init, etl::ipool& node_pool)
1909 : etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1910 {
1911 this->assign(init.begin(), init.end());
1912 }
1913#endif
1914
1915 //*************************************************************************
1917 //*************************************************************************
1919 {
1920 this->initialise();
1921 }
1922
1923 //*************************************************************************
1925 //*************************************************************************
1927 {
1928 if (&rhs != this)
1929 {
1930 this->assign(rhs.cbegin(), rhs.cend());
1931 }
1932
1933 return *this;
1934 }
1935
1936#if ETL_USING_CPP11
1937 //*************************************************************************
1939 //*************************************************************************
1941 {
1942 this->move_container(etl::move(rhs));
1943
1944 return *this;
1945 }
1946#endif
1947
1948 //*************************************************************************
1950 //*************************************************************************
1952 {
1953 // Clear the list of any current elements.
1954 if (this->get_node_pool() != ETL_NULLPTR)
1955 {
1956 this->clear();
1957 }
1958
1959 this->set_node_pool(pool);
1960 }
1961
1962 //*************************************************************************
1964 //*************************************************************************
1966 {
1967 return *this->p_node_pool;
1968 }
1969 };
1970
1971 //*************************************************************************
1976 //*************************************************************************
1977 template <typename T>
1979 {
1980 return (lhs.size() == rhs.size()) &&
1981 etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1982 }
1983
1984 //*************************************************************************
1989 //*************************************************************************
1990 template <typename T>
1992 {
1993 return !(lhs == rhs);
1994 }
1995
1996 //*************************************************************************
2002 //*************************************************************************
2003 template <typename T>
2005 {
2006 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
2007 }
2008
2009 //*************************************************************************
2015 //*************************************************************************
2016 template <typename T>
2018 {
2019 return (rhs < lhs);
2020 }
2021
2022 //*************************************************************************
2028 //*************************************************************************
2029 template <typename T>
2031 {
2032 return !(lhs > rhs);
2033 }
2034
2035 //*************************************************************************
2041 //*************************************************************************
2042 template <typename T>
2044 {
2045 return !(lhs < rhs);
2046 }
2047}
2048
2049#include "private/minmax_pop.h"
2050
2051#endif
Template deduction guides.
Definition forward_list.h:1809
void set_pool(etl::ipool &pool)
Set the pool instance.
Definition forward_list.h:1951
etl::ipool & get_pool() const
Get the pool instance.
Definition forward_list.h:1965
forward_list_ext()
Default constructor.
Definition forward_list.h:1824
forward_list_ext(etl::ipool &node_pool)
Default constructor.
Definition forward_list.h:1832
forward_list_ext(size_t initial_size, const T &value, etl::ipool &node_pool)
Construct from size and value.
Definition forward_list.h:1850
forward_list_ext(TIterator first, TIterator last, etl::ipool &node_pool, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Construct from range.
Definition forward_list.h:1898
forward_list_ext(const forward_list_ext &other)
Copy constructor. Implicit pool.
Definition forward_list.h:1859
forward_list_ext(size_t initial_size, etl::ipool &node_pool)
Construct from size.
Definition forward_list.h:1841
forward_list_ext(const forward_list_ext &other, etl::ipool &node_pool)
Copy constructor. Explicit pool.
Definition forward_list.h:1868
~forward_list_ext()
Destructor.
Definition forward_list.h:1918
Definition forward_list.h:1666
~forward_list()
Destructor.
Definition forward_list.h:1744
forward_list(size_t initial_size, const T &value=T())
Construct from size and value.
Definition forward_list.h:1694
forward_list(const forward_list &other)
Copy constructor.
Definition forward_list.h:1703
forward_list()
Default constructor.
Definition forward_list.h:1685
forward_list(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Construct from range.
Definition forward_list.h:1724
const_iterator
Definition forward_list.h:472
iterator.
Definition forward_list.h:398
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:968
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
iterator end()
Gets the end of the forward_list.
Definition forward_list.h:596
void resize(size_t n)
Resizes the forward_list.
Definition forward_list.h:831
reference emplace_front(const T1 &value1)
Emplaces a value to the front of the list..
Definition forward_list.h:756
size_type MAX_SIZE
The maximum size of the forward_list.
Definition forward_list.h:353
void unique(TIsEqual isEqual)
Definition forward_list.h:1193
void assign(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Definition forward_list.h:647
iforward_list & operator=(const iforward_list &rhs)
Assignment operator.
Definition forward_list.h:1414
iterator emplace_after(const_iterator position, const T1 &value1)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:933
forward_list_base(bool pool_is_shared_)
The constructor that is called from derived classes.
Definition forward_list.h:268
reference emplace_front(const T1 &value1, const T2 &value2, const T3 &value3)
Emplaces a value to the front of the list..
Definition forward_list.h:788
const_iterator cbegin() const
Gets the beginning of the forward_list.
Definition forward_list.h:588
iterator before_begin()
Gets before the beginning of the forward_list.
Definition forward_list.h:572
iterator erase_after(iterator position)
Erases the value at the specified position.
Definition forward_list.h:1042
void insert_node_after(node_t &position, node_t &node)
Insert a node.
Definition forward_list.h:311
iterator erase_after(const_iterator position)
Erases the value at the specified position.
Definition forward_list.h:1061
iterator emplace_after(const_iterator position, const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:981
void unique()
Definition forward_list.h:1183
node_t start_node
The node that acts as the forward_list start.
Definition forward_list.h:351
iterator insert_after(const_iterator position, size_t n, const T &value)
Inserts 'n' copies of a value to the forward_list after the specified position.
Definition forward_list.h:997
size_type max_size() const
Gets the maximum possible size of the forward_list.
Definition forward_list.h:169
forward_list_base(etl::ipool &node_pool_, size_type max_size_, bool pool_is_shared_)
The constructor that is called from derived classes.
Definition forward_list.h:278
reference emplace_front(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Emplaces a value to the front of the list..
Definition forward_list.h:804
void resize(size_t n, T value)
Definition forward_list.h:841
iforward_list(etl::ipool &node_pool, size_t max_size_, bool pool_is_shared_)
Constructor.
Definition forward_list.h:1449
size_t available() const
Definition forward_list.h:229
ETL_DECLARE_DEBUG_COUNT
Internal debugging.
Definition forward_list.h:355
size_type capacity() const
Gets the maximum possible size of the forward_list.
Definition forward_list.h:177
void clear()
Clears the forward_list.
Definition forward_list.h:620
iterator emplace_after(const_iterator position)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:917
iterator emplace_after(const_iterator position, const T1 &value1, const T2 &value2)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:949
node_t * get_head()
Get the head node.
Definition forward_list.h:295
const_iterator before_begin() const
Gets before the beginning of the forward_list.
Definition forward_list.h:580
etl::ipool * get_node_pool()
Get the node pool instance.
Definition forward_list.h:346
void reverse()
Reverses the forward_list.
Definition forward_list.h:238
const_iterator cend() const
Gets the end of the forward_list.
Definition forward_list.h:612
const_iterator begin() const
Gets the beginning of the forward_list.
Definition forward_list.h:564
void join(node_t *left, node_t *right)
Join two nodes.
Definition forward_list.h:329
size_t size_type
The type used for determining the size of forward_list.
Definition forward_list.h:156
reference front()
Gets a reference to the first element.
Definition forward_list.h:628
void move_after(const_iterator first_before, const_iterator last, const_iterator to_before)
Definition forward_list.h:1144
bool pool_is_shared
If true then the pool is shared between lists.
Definition forward_list.h:354
void push_front(const T &value)
Pushes a value to the front of the forward_list.
Definition forward_list.h:695
iterator insert_after(const_iterator position, const T &value)
Inserts a value to the forward_list after the specified position.
Definition forward_list.h:887
reference emplace_front(const T1 &value1, const T2 &value2)
Emplaces a value to the front of the list..
Definition forward_list.h:772
iterator emplace_after(const_iterator position, const T1 &value1, const T2 &value2, const T3 &value3)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:965
void sort()
Definition forward_list.h:1224
void sort(TCompare compare)
Definition forward_list.h:1255
void initialise()
Initialise the forward_list.
Definition forward_list.h:1457
etl::ipool * p_node_pool
The pool of data nodes used in the list.
Definition forward_list.h:352
const_reference front() const
Gets a const reference to the first element.
Definition forward_list.h:636
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition forward_list.h:1392
bool has_shared_pool() const
true if the list has a shared pool.
Definition forward_list.h:161
bool full() const
Checks to see if the forward_list is full.
Definition forward_list.h:219
void pop_front()
Removes a value from the front of the forward_list.
Definition forward_list.h:820
iterator insert_after(const_iterator position, TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Inserts a range of values to the forward_list after the specified position.
Definition forward_list.h:1020
~forward_list_base()
Destructor.
Definition forward_list.h:288
iterator erase_after(const_iterator first, const_iterator last)
Erases a range of elements.
Definition forward_list.h:1080
bool empty() const
Checks to see if the forward_list is empty.
Definition forward_list.h:211
void assign(size_t n, const T &value)
Assigns 'n' copies of a value to the forward_list.
Definition forward_list.h:674
void set_node_pool(etl::ipool &node_pool_)
Set the node pool instance.
Definition forward_list.h:337
void move_after(const_iterator from_before, const_iterator to_before)
Definition forward_list.h:1120
~iforward_list()
Destructor.
Definition forward_list.h:1644
reference emplace_front()
Emplaces a value to the front of the list..
Definition forward_list.h:740
size_type size() const
Gets the size of the forward_list.
Definition forward_list.h:185
data_node_t & allocate_data_node(const_reference value)
Allocate a data_node_t.
Definition forward_list.h:1488
const_iterator end() const
Gets the end of the forward_list.
Definition forward_list.h:604
iterator begin()
Gets the beginning of the forward_list.
Definition forward_list.h:556
iforward_list(bool pool_is_shared_)
Constructor.
Definition forward_list.h:1441
const node_t * get_head() const
Get the head node.
Definition forward_list.h:303
bool is_trivial_list() const
Is the forward_list a trivial length?
Definition forward_list.h:321
Definition forward_list.h:138
Definition forward_list.h:96
Definition forward_list.h:68
Definition forward_list.h:82
Definition forward_list.h:110
Definition forward_list.h:364
Definition forward_list.h:124
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:301
void release_all()
Release all objects in the pool.
Definition ipool.h:248
bool full() const
Definition ipool.h:319
size_t max_size() const
Returns the maximum number of items in the pool.
Definition ipool.h:269
void release(const void *const p_object)
Definition ipool.h:239
size_t available() const
Returns the number of free items in the pool.
Definition ipool.h:293
Definition ipool.h:102
Definition pool.h:54
enable_if
Definition type_traits_generator.h:1186
is_integral
Definition type_traits_generator.h:996
bitset_ext
Definition absolute.h:38
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:693
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool_generator.h:395
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:705
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:666
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:681
Definition compare.h:51
The node element in the forward_list.
Definition forward_list.h:145
The data node element in the forward_list.
Definition forward_list.h:384
Definition type_traits_generator.h:2096
iterator
Definition iterator.h:399
pair holds two objects of arbitrary type
Definition utility.h:164