31#ifndef ETL_LIST_INCLUDED
32#define ETL_LIST_INCLUDED
47#include "static_assert.h"
167 : previous(ETL_NULLPTR),
177 using ETL_OR_STD::swap;
179 swap(previous, next);
209 p_node->previous = p_node->next;
211 p_node = p_node->previous;
216 p_node->previous = p_node->next;
251 p_node = p_node->next;
347 right.previous = &left;
400 ETL_DECLARE_DEBUG_COUNT
407 template <
typename T>
452 static data_node_t& data_cast(node_t&
node)
454 return reinterpret_cast<data_node_t&
>(
node);
460 static const data_node_t* data_cast(
const node_t* p_node)
462 return reinterpret_cast<const data_node_t*
>(p_node);
468 static const data_node_t& data_cast(
const node_t& node)
470 return reinterpret_cast<const data_node_t&
>(node);
486 : p_node(ETL_NULLPTR)
496 : p_node(
other.p_node)
502 p_node = p_node->next;
509 p_node = p_node->next;
515 p_node = p_node->previous;
522 p_node = p_node->previous;
528 p_node =
other.p_node;
534 return ilist::data_cast(p_node)->value;
539 return &(ilist::data_cast(p_node)->value);
544 return &(ilist::data_cast(p_node)->value);
549 return lhs.p_node ==
rhs.p_node;
572 : p_node(ETL_NULLPTR)
587 : p_node(
other.p_node)
592 : p_node(
other.p_node)
598 p_node = p_node->next;
605 p_node = p_node->next;
611 p_node = p_node->previous;
618 p_node = p_node->previous;
624 p_node =
other.p_node;
630 return ilist::data_cast(p_node)->value;
635 return &(ilist::data_cast(p_node)->value);
640 return &(ilist::data_cast(p_node)->value);
645 return lhs.p_node ==
rhs.p_node;
658 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
660 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
661 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
732 return reverse_iterator(
get_head());
738 const_reverse_iterator
rend()
const
740 return const_reverse_iterator(
get_head());
754 const_reverse_iterator
crend()
const
756 return const_reverse_iterator(
get_head());
796 template <
typename TIterator>
799#if ETL_IS_DEBUG_BUILD
800 difference_type
d = etl::distance(first, last);
807 while (first != last)
821#if ETL_IS_DEBUG_BUILD
841#if defined(ETL_CHECK_PUSH_POP)
853#if defined(ETL_CHECK_PUSH_POP)
860#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
864 template <
typename ... Args>
867#if defined(ETL_CHECK_PUSH_POP)
872 data_node_t* p_data_node = allocate_data_node();
873 ::new (&(p_data_node->value)) T(
etl::forward<Args>(args)...);
874 ETL_INCREMENT_DEBUG_COUNT
882 template <
typename T1>
885#if defined(ETL_CHECK_PUSH_POP)
892 ETL_INCREMENT_DEBUG_COUNT
900 template <
typename T1,
typename T2>
903#if defined(ETL_CHECK_PUSH_POP)
910 ETL_INCREMENT_DEBUG_COUNT
918 template <
typename T1,
typename T2,
typename T3>
921#if defined(ETL_CHECK_PUSH_POP)
927 ::new (&(
p_data_node->value))
T(value1, value2, value3);
928 ETL_INCREMENT_DEBUG_COUNT
936 template <
typename T1,
typename T2,
typename T3,
typename T4>
939#if defined(ETL_CHECK_PUSH_POP)
945 ::new (&(
p_data_node->value))
T(value1, value2, value3, value4);
946 ETL_INCREMENT_DEBUG_COUNT
957#if defined(ETL_CHECK_PUSH_POP)
969#if defined(ETL_CHECK_PUSH_POP)
981#if defined(ETL_CHECK_PUSH_POP)
991#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
992 template <
typename ... Args>
995#if defined(ETL_CHECK_PUSH_POP)
1000 data_node_t* p_data_node = allocate_data_node();
1001 ::new (&(p_data_node->value)) T(
etl::forward<Args>(args)...);
1002 ETL_INCREMENT_DEBUG_COUNT
1007 template <
typename T1>
1010#if defined(ETL_CHECK_PUSH_POP)
1017 ETL_INCREMENT_DEBUG_COUNT
1022 template <
typename T1,
typename T2>
1025#if defined(ETL_CHECK_PUSH_POP)
1032 ETL_INCREMENT_DEBUG_COUNT
1040#if defined(ETL_CHECK_PUSH_POP)
1046 ::new (&(
p_data_node->value))
T(value1, value2, value3);
1047 ETL_INCREMENT_DEBUG_COUNT
1055#if defined(ETL_CHECK_PUSH_POP)
1061 ::new (&(
p_data_node->value))
T(value1, value2, value3, value4);
1062 ETL_INCREMENT_DEBUG_COUNT
1073#if defined(ETL_CHECK_PUSH_POP)
1101 data_node_t&
data_node = allocate_data_node(etl::move(value));
1111#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
1112 template <
typename ... Args>
1113 iterator
emplace(const_iterator position, Args && ... args)
1118 data_node_t* p_data_node = allocate_data_node();
1119 ::new (&(p_data_node->value)) T(
etl::forward<Args>(args)...);
1120 ETL_INCREMENT_DEBUG_COUNT
1121 insert_node(*to_iterator(position).p_node, *p_data_node);
1123 return iterator(*p_data_node);
1126 template <
typename T1>
1134 ETL_INCREMENT_DEBUG_COUNT
1140 template <
typename T1,
typename T2>
1148 ETL_INCREMENT_DEBUG_COUNT
1161 ::new (&(
p_data_node->value))
T(value1, value2, value3);
1162 ETL_INCREMENT_DEBUG_COUNT
1175 ::new (&(
p_data_node->value))
T(value1, value2, value3, value4);
1176 ETL_INCREMENT_DEBUG_COUNT
1188 for (
size_t i = 0
UL;
i <
n; ++
i)
1193 insert_node(*to_iterator(position).p_node, allocate_data_node(value));
1200 template <
typename TIterator>
1203 while (first != last)
1208 insert_node(*to_iterator(position).p_node, allocate_data_node(*first));
1221 remove_node(*
position_.p_node->previous);
1272 else if (
n <
size())
1279 else if (
n >
size())
1296 void remove(const_reference value)
1316 template <
typename TPredicate>
1347 template <
typename TIsEqual>
1394 while (itr !=
other.end())
1400 other.erase(other.begin(), other.end());
1437 insert(to, etl::move(*from));
1451 move(
to, first, last);
1457 other.erase(first, last);
1470 move(
to, first, last);
1475 ilist::iterator itr = first;
1478 to =
insert(to, etl::move(*itr));
1483 other.erase(first, last);
1499 template <
typename TCompare>
1504#if ETL_IS_DEBUG_BUILD
1556 template <
typename TCompare>
1557 void merge(ilist&& other, TCompare compare)
1561#if ETL_IS_DEBUG_BUILD
1566 ilist::iterator other_begin = other.begin();
1567 ilist::iterator other_end = other.end();
1569 ilist::iterator this_begin =
begin();
1570 ilist::iterator this_end =
end();
1572 while ((this_begin != this_end) && (other_begin != other_end))
1575 while ((this_begin != this_end) && !(compare(*other_begin, *this_begin)))
1581 if (this_begin != this_end)
1583 while ((other_begin != other_end) && (compare(*other_begin, *this_begin)))
1585 insert(this_begin, etl::move(*other_begin));
1592 if ((this_begin == this_end) && (other_begin != other_end))
1594 while (other_begin != other_end)
1596 insert(this_end, etl::move(*other_begin));
1640 template <
typename TCompare>
1772 while (itr !=
rhs.end())
1816 ETL_RESET_DEBUG_COUNT;
1854 ETL_SET_DEBUG_COUNT(ETL_OBJECT_GET_DEBUG_COUNT(
rhs));
1857 ETL_OBJECT_RESET_DEBUG_COUNT(
rhs);
1858 rhs.join(
rhs.terminal_node,
rhs.terminal_node);
1866 while (first != last)
1887 void move(iterator to, iterator from)
1894 node_t& from_node = *from.p_node;
1895 node_t& to_node = *to.p_node;
1898 join(*from_node.previous, *from_node.next);
1901 join(*to_node.previous, from_node);
1902 join(from_node, to_node);
1909 void move(iterator to, iterator first, iterator last)
1911 if ((first == to) || (last == to))
1916#if ETL_IS_DEBUG_BUILD
1918 for (const_iterator item = first; item != last; ++item)
1920 ETL_ASSERT(item != to, ETL_ERROR(list_iterator));
1924 node_t& first_node = *first.p_node;
1925 node_t& last_node = *last.p_node;
1926 node_t& to_node = *to.p_node;
1927 node_t& final_node = *last_node.previous;
1930 join(*first_node.previous, last_node);
1933 join(*to_node.previous, first_node);
1934 join(final_node, to_node);
1940 void remove_node(node_t& node)
1943 join(*node.previous, *node.next);
1946 destroy_data_node(
static_cast<data_node_t&
>(node));
1952 data_node_t& allocate_data_node(const_reference value)
1956 data_node_t* p_data_node = allocate_data_node();
1957 ::new (&(p_data_node->value)) T(value);
1958 ETL_INCREMENT_DEBUG_COUNT
1960 return *p_data_node;
1967 data_node_t& allocate_data_node(rvalue_reference value)
1971 data_node_t* p_data_node = allocate_data_node();
1972 ::new (&(p_data_node->value)) T(
etl::move(value));
1973 ETL_INCREMENT_DEBUG_COUNT
1975 return *p_data_node;
1982 data_node_t* allocate_data_node()
1984 data_node_t* (
etl::ipool::*func)() = &etl::ipool::allocate<data_node_t>;
1991 void destroy_data_node(data_node_t& node)
1996 ETL_DECREMENT_DEBUG_COUNT
2000 ilist(
const ilist&);
2002#if defined(ETL_POLYMORPHIC_LIST) || defined(ETL_POLYMORPHIC_CONTAINERS)
2019 iterator to_iterator(const_iterator itr)
const
2021 return iterator(*(
const_cast<node_t*
>(itr.p_node)));
2028 template <
typename T, const
size_t MAX_SIZE_>
2033 ETL_STATIC_ASSERT((
MAX_SIZE_ > 0U),
"Zero capacity etl::list is not valid");
2035 static ETL_CONSTANT
size_t MAX_SIZE =
MAX_SIZE_;
2107 while (itr !=
other.end())
2109 this->push_back(etl::move(*itr));
2121 template <
typename TIterator>
2125 this->assign(first, last);
2128#if ETL_HAS_INITIALIZER_LIST
2132 list(std::initializer_list<T>
init)
2135 this->assign(
init.begin(),
init.end());
2146 this->assign(
rhs.cbegin(),
rhs.cend());
2170 template <
typename T, const
size_t MAX_SIZE_>
2171 ETL_CONSTANT
size_t list<T, MAX_SIZE_>::MAX_SIZE;
2176#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
2177 template <
typename... T>
2185#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
2186 template <
typename... T>
2196 template <
typename T>
2289 list_ext(list_ext&& other,
etl::ipool& node_pool)
2290 :
etl::ilist<T>(node_pool, node_pool.max_size(), true)
2292 this->move_container(etl::move(other));
2299 template <
typename TIterator>
2303 this->assign(first, last);
2306#if ETL_HAS_INITIALIZER_LIST
2313 this->assign(
init.begin(),
init.end());
2324 this->assign(
rhs.cbegin(),
rhs.cend());
2348 if (this->get_node_pool() != ETL_NULLPTR)
2353 this->set_node_pool(
pool);
2361 return *this->p_node_pool;
2371 template <
typename T>
2374 return (
lhs.size() ==
rhs.size()) && etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
2383 template <
typename T>
2396 template <
typename T>
2399 return etl::lexicographical_compare(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
2409 template <
typename T>
2422 template <
typename T>
2435 template <
typename T>
const_iterator
Definition list.h:566
iterator.
Definition list.h:479
Template deduction guides.
Definition list.h:2198
list_ext(const list_ext &other, etl::ipool &node_pool)
Copy constructor. Explicit pool.
Definition list.h:2267
list_ext(size_t initial_size, etl::ipool &node_pool)
Construct from size.
Definition list.h:2237
void set_pool(etl::ipool &pool)
Set the pool instance.
Definition list.h:2345
list_ext(size_t initial_size, const T &value, etl::ipool &node_pool)
Construct from size and value.
Definition list.h:2246
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 list.h:2300
list_ext()
Default constructor.
Definition list.h:2213
etl::ipool & get_pool() const
Get the pool instance.
Definition list.h:2359
list_ext(etl::ipool &node_pool)
Default constructor.
Definition list.h:2221
~list_ext()
Destructor.
Definition list.h:2229
list_ext(const list_ext &other)
Copy constructor. Implicit pool.
Definition list.h:2255
A templated list implementation that uses a fixed size buffer.
Definition list.h:2030
~list()
Destructor.
Definition list.h:2060
list(const list &other)
Copy constructor.
Definition list.h:2086
list(size_t initial_size, const T &value)
Construct from size and value.
Definition list.h:2077
list(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Construct from range.
Definition list.h:2122
list(size_t initial_size)
Construct from size.
Definition list.h:2068
list()
Default constructor.
Definition list.h:2052
ETL_CONSTEXPR14 bool operator==(const etl::unexpected< TError > &lhs, const etl::unexpected< TError > &rhs)
Equivalence operator.
Definition expected.h:950
ETL_NODISCARD ETL_CONSTEXPR14 bool is_sorted(TIterator begin, TIterator end)
Definition algorithm.h:1441
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
ilist(etl::ipool &node_pool, size_t max_size_, bool pool_is_shared_)
Constructor.
Definition list.h:1798
const_reverse_iterator rend() const
Gets the reverse end of the list.
Definition list.h:738
void clear()
Clears the list.
Definition list.h:1288
const_iterator cbegin() const
Gets the beginning of the list.
Definition list.h:698
iterator end()
Gets the end of the list.
Definition list.h:682
void push_back(const T &value)
Pushes a value to the back of the list.
Definition list.h:967
ilist(bool pool_is_shared_)
Constructor.
Definition list.h:1790
reference back()
Gets a reference to the last element.
Definition list.h:778
size_t size_type
The type used for determining the size of list.
Definition list.h:156
void reverse()
Reverses the list.
Definition list.h:197
const_reverse_iterator crend() const
Gets the reverse end of the list.
Definition list.h:754
iterator emplace(const_iterator position, const T1 &value1)
Emplaces a value to the list at the specified position.
Definition list.h:1127
reference emplace_front(const T1 &value1)
Emplaces a value to the front of the list.
Definition list.h:883
void splice(iterator to, ilist &other, iterator from)
Splices an element from another list to this.
Definition list.h:1408
size_type size() const
Gets the size of the list.
Definition list.h:239
void sort(TCompare compare)
Definition list.h:1641
size_type available() const
Definition list.h:283
void splice(iterator to, ilist &other, iterator first, iterator last)
Splices a range of elements from another list to this.
Definition list.h:1446
void join(node_t &left, node_t &right)
Join two nodes.
Definition list.h:344
void insert(const_iterator position, size_t n, const_reference value)
Inserts 'n' copies of a value to the list at the specified position.
Definition list.h:1186
void unique(TIsEqual isEqual)
Definition list.h:1348
void insert(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 list at the specified position.
Definition list.h:1201
const_reverse_iterator rbegin() const
Gets the reverse beginning of the list.
Definition list.h:722
list_base(bool pool_is_shared_)
The constructor that is called from derived classes.
Definition list.h:353
etl::ipool * p_node_pool
The pool of data nodes used in the list.
Definition list.h:396
size_type max_size() const
Gets the maximum possible size of the list.
Definition list.h:223
void resize(size_t n)
Resizes the list.
Definition list.h:1254
list_base(etl::ipool &node_pool_, size_type max_size_, bool pool_is_shared_)
The constructor that is called from derived classes.
Definition list.h:364
bool full() const
Checks to see if the list is full.
Definition list.h:273
reverse_iterator rend()
Gets the reverse end of the list.
Definition list.h:730
reverse_iterator rbegin()
Gets the reverse beginning of the list.
Definition list.h:714
ilist & operator=(const ilist &rhs)
Assignment operator.
Definition list.h:1751
iterator insert(const_iterator position, const_reference value)
Inserts a value to the list at the specified position.
Definition list.h:1083
size_type MAX_SIZE
The maximum size of the list.
Definition list.h:398
node_t terminal_node
The node that acts as the list start and end.
Definition list.h:397
void push_front(const T &value)
Pushes a value to the front of the list.
Definition list.h:839
void initialise()
Initialise the list.
Definition list.h:1806
reference emplace_back(const T1 &value1)
Emplaces a value to the back of the list.
Definition list.h:1008
bool pool_is_shared
If true then the pool is shared between lists.
Definition list.h:399
void splice(iterator to, ilist &other)
Splices from another list to this.
Definition list.h:1376
const_iterator end() const
Gets the end of the list.
Definition list.h:690
reference front()
Gets a reference to the first element.
Definition list.h:762
void pop_front()
Removes a value from the front of the list.
Definition list.h:955
const_iterator begin() const
Gets the beginning of the list.
Definition list.h:674
void merge(ilist &other)
Merge another list into this one. Both lists should be sorted.
Definition list.h:1491
bool is_trivial_list() const
Is the list a trivial length?
Definition list.h:294
void assign(size_t n, const T &value)
Assigns 'n' copies of a value to the list.
Definition list.h:819
iterator erase(const_iterator first, const_iterator last)
Erases a range of elements.
Definition list.h:1228
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 list.h:937
void set_node_pool(etl::ipool &node_pool_)
Set the node pool instance.
Definition list.h:375
reference emplace_front(const T1 &value1, const T2 &value2, const T3 &value3)
Emplaces a value to the front of the list.
Definition list.h:919
void merge(ilist &other, TCompare compare)
Merge another list into this one. Both lists should be sorted.
Definition list.h:1500
void resize(size_t n, const_reference value)
Resizes the list.
Definition list.h:1262
size_type capacity() const
Gets the maximum possible size of the list.
Definition list.h:231
bool empty() const
Checks to see if the list is empty.
Definition list.h:265
etl::ipool * get_node_pool()
Get the node pool instance.
Definition list.h:384
iterator begin()
Gets the beginning of the list.
Definition list.h:666
void sort()
Definition list.h:1610
const_reference back() const
Gets a reference to the last element.
Definition list.h:786
void unique()
Definition list.h:1338
const_reference front() const
Gets a const reference to the first element.
Definition list.h:770
node_t & get_head()
Get the head node.
Definition list.h:302
const node_t & get_head() const
Get the head node.
Definition list.h:310
void insert_node(node_t &position, node_t &node)
Insert a node before 'position'.
Definition list.h:334
const node_t & get_tail() const
Get the tail node.
Definition list.h:326
const_iterator cend() const
Gets the end of the list.
Definition list.h:706
const_reverse_iterator crbegin() const
Gets the reverse beginning of the list.
Definition list.h:746
~list_base()
Destructor.
Definition list.h:392
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition list.h:1317
void assign(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Definition list.h:797
node_t & get_tail()
Get the tail node.
Definition list.h:318
iterator erase(const_iterator position)
Erases the value at the specified position.
Definition list.h:1216
bool has_shared_pool() const
true if the list has a shared pool.
Definition list.h:189
void pop_back()
Removes a value from the back of the list.
Definition list.h:1071
reference emplace_front(const T1 &value1, const T2 &value2)
Emplaces a value to the front of the list.
Definition list.h:901
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:293
void release_all()
Release all objects in the pool.
Definition ipool.h:248
bool full() const
Definition ipool.h:311
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:285
enable_if
Definition type_traits_generator.h:1191
is_integral
Definition type_traits_generator.h:1001
bitset_ext
Definition absolute.h:38
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:684
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool_generator.h:281
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:696
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:645
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:621
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:633
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:657
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:672
The data node element in the list.
Definition list.h:430
Definition type_traits_generator.h:2055
iterator
Definition iterator.h:399
The node element in the list.
Definition list.h:162
void reverse()
Reverses the previous & next pointers.
Definition list.h:175
node_t()
Constructor.
Definition list.h:166
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR14 bool operator!=(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Inequality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:1017