31#ifndef ETL_FORWARD_LIST_INCLUDED
32#define ETL_FORWARD_LIST_INCLUDED
47#include "static_assert.h"
194 while (p_node != ETL_NULLPTR)
197 p_node = p_node->next;
247 node_t* p_next = p_current->next;
249 p_current->next = ETL_NULLPTR;
251 while (p_next != ETL_NULLPTR)
255 p_next = p_current->next;
362 template <
typename T>
367 typedef T value_type;
369 typedef const T* const_pointer;
370 typedef T& reference;
371 typedef const T& const_reference;
372 typedef size_t size_type;
405 : p_node(ETL_NULLPTR)
415 : p_node(
other.p_node)
421 p_node = p_node->next;
428 p_node = p_node->next;
434 p_node =
other.p_node;
438 reference operator *()
const
440 return iforward_list::data_cast(p_node)->value;
443 pointer operator &()
const
445 return &(iforward_list::data_cast(p_node)->value);
448 pointer operator ->()
const
450 return &(iforward_list::data_cast(p_node)->value);
455 return lhs.p_node ==
rhs.p_node;
478 : p_node(ETL_NULLPTR)
493 : p_node(
other.p_node)
498 : p_node(
other.p_node)
504 p_node = p_node->next;
511 p_node = p_node->next;
517 p_node =
other.p_node;
521 const_reference operator *()
const
523 return iforward_list::data_cast(p_node)->value;
526 const_pointer operator &()
const
528 return &(iforward_list::data_cast(p_node)->value);
531 const_pointer operator ->()
const
533 return &(iforward_list::data_cast(p_node)->value);
538 return lhs.p_node ==
rhs.p_node;
551 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
630 return data_cast(*
get_head()).value;
638 return data_cast(*
get_head()).value;
646 template <
typename TIterator>
649#if ETL_IS_DEBUG_BUILD
650 difference_type d = etl::distance(first, last);
659 while (first != last)
711 data_node_t&
data_node = allocate_data_node(etl::move(value));
716#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
720 template <
typename ...
Args>
723 ETL_ASSERT_CHECK_PUSH_POP(!
full(), ETL_ERROR(forward_list_full));
727 ETL_INCREMENT_DEBUG_COUNT;
741 ETL_INCREMENT_DEBUG_COUNT;
749 template <
typename T1>
756 ETL_INCREMENT_DEBUG_COUNT;
764 template <
typename T1,
typename T2>
771 ETL_INCREMENT_DEBUG_COUNT;
779 template <
typename T1,
typename T2,
typename T3>
786 ETL_INCREMENT_DEBUG_COUNT;
794 template <
typename T1,
typename T2,
typename T3,
typename T4>
801 ETL_INCREMENT_DEBUG_COUNT;
886#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
890 template <
typename ...
Args>
897 ETL_INCREMENT_DEBUG_COUNT;
912 ETL_INCREMENT_DEBUG_COUNT;
921 template <
typename T1>
928 ETL_INCREMENT_DEBUG_COUNT;
937 template <
typename T1,
typename T2>
944 ETL_INCREMENT_DEBUG_COUNT;
953 template <
typename T1,
typename T2,
typename T3>
960 ETL_INCREMENT_DEBUG_COUNT;
969 template <
typename T1,
typename T2,
typename T3,
typename T4>
976 ETL_INCREMENT_DEBUG_COUNT;
990 for (
size_t i = 0
UL; !
full() && (i <
n); ++i)
1002 return to_iterator(position);
1008 template <
typename TIterator>
1011#if ETL_IS_DEBUG_BUILD
1012 difference_type d = etl::distance(first, last);
1016 while (first != last)
1025 return to_iterator(position);
1040 remove_node_after(*position.p_node);
1059 remove_node_after(*position.p_node);
1071 if (first !=
end() && (first != last))
1090 if (p_next == ETL_NULLPTR)
1181 template <
typename TIsEqual>
1190 node_t* current = last->next;
1192 while (current != ETL_NULLPTR)
1195 if (
isEqual(data_cast(current)->value, data_cast(last)->value))
1197 remove_node_after(*last);
1205 current = last->next;
1243 template <
typename TCompare>
1337 p_tail.p_node->next = ETL_NULLPTR;
1358 void remove(
const T& value)
1380 template <
typename TPredicate>
1454 ETL_RESET_DEBUG_COUNT;
1462 while (
p_first != ETL_NULLPTR)
1480 ::new (&(p_node->value))
T(value);
1481 ETL_INCREMENT_DEBUG_COUNT;
1492 data_node_t* p_node = allocate_data_node();
1493 ::new (&(p_node->value))
T(
etl::move(value));
1494 ETL_INCREMENT_DEBUG_COUNT;
1516 this->start_node.next =
rhs.start_node.next;
1518 ETL_SET_DEBUG_COUNT(ETL_OBJECT_GET_DEBUG_COUNT(
rhs));
1520 ETL_OBJECT_RESET_DEBUG_COUNT(
rhs);
1521 rhs.start_node.next = ETL_NULLPTR;
1531 while (first != last)
1535 data_node_t&
data_node = this->allocate_data_node(etl::move(*first));
1554 static data_node_t* data_cast(node_t* p_node)
1556 return static_cast<data_node_t*
>(p_node);
1562 static data_node_t& data_cast(node_t&
node)
1564 return static_cast<data_node_t&
>(
node);
1570 static const data_node_t* data_cast(
const node_t* p_node)
1572 return static_cast<const data_node_t*
>(p_node);
1578 static const data_node_t& data_cast(
const node_t&
node)
1580 return static_cast<const data_node_t&
>(
node);
1586 void remove_node_after(node_t&
node)
1589 node_t* p_node =
node.next;
1591 if (p_node != ETL_NULLPTR)
1597 destroy_data_node(
static_cast<data_node_t&
>(*p_node));
1606 data_node_t* (
etl::ipool::*
func)() = &etl::ipool::allocate<data_node_t>;
1613 void destroy_data_node(data_node_t&
node)
1617 ETL_DECREMENT_DEBUG_COUNT;
1626#if defined(ETL_POLYMORPHIC_FORWARD_LIST) || defined(ETL_POLYMORPHIC_CONTAINERS)
1643 iterator to_iterator(const_iterator itr)
const
1645 return iterator(
const_cast<node_t*
>(itr.p_node));
1653 template <
typename T, const
size_t MAX_SIZE_>
1658 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U),
"Zero capacity etl::forward_list is not valid");
1660 static ETL_CONSTANT
size_t MAX_SIZE = MAX_SIZE_;
1664 typedef T value_type;
1666 typedef const T* const_pointer;
1667 typedef T& reference;
1668 typedef const T& const_reference;
1669 typedef size_t size_type;
1686 this->assign(initial_size, value);
1705 this->move_container(etl::move(other));
1712 template <
typename TIterator>
1716 this->assign(first, last);
1719#if ETL_HAS_INITIALIZER_LIST
1726 this->assign(init.begin(), init.end());
1758 this->move_container(etl::move(rhs));
1770 template <
typename T, const
size_t MAX_SIZE_>
1771 ETL_CONSTANT
size_t forward_list<T, MAX_SIZE_>::MAX_SIZE;
1776#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1777 template <
typename...
T>
1784#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1785 template <
typename...
T>
1796 template <
typename T>
1801 typedef T value_type;
1803 typedef const T* const_pointer;
1804 typedef T& reference;
1805 typedef const T& const_reference;
1806 typedef size_t size_type;
1833 this->assign(initial_size, T());
1842 this->assign(initial_size, value);
1870 this->move_container(etl::move(other));
1876 forward_list_ext(forward_list_ext&& other,
etl::ipool& node_pool)
1877 :
etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
1879 this->move_container(etl::move(other));
1886 template <
typename TIterator>
1890 this->assign(first, last);
1893#if ETL_HAS_INITIALIZER_LIST
1900 this->assign(init.begin(), init.end());
1931 this->move_container(etl::move(rhs));
1943 if (this->get_node_pool() != ETL_NULLPTR)
1948 this->set_node_pool(
pool);
1956 return *this->p_node_pool;
1966 template <
typename T>
1969 return (
lhs.size() ==
rhs.size()) &&
1970 etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
1979 template <
typename T>
1992 template <
typename T>
1995 return etl::lexicographical_compare(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
2005 template <
typename T>
2018 template <
typename T>
2031 template <
typename T>
Template deduction guides.
Definition forward_list.h:1798
void set_pool(etl::ipool &pool)
Set the pool instance.
Definition forward_list.h:1940
etl::ipool & get_pool() const
Get the pool instance.
Definition forward_list.h:1954
forward_list_ext()
Default constructor.
Definition forward_list.h:1813
forward_list_ext(etl::ipool &node_pool)
Default constructor.
Definition forward_list.h:1821
forward_list_ext(size_t initial_size, const T &value, etl::ipool &node_pool)
Construct from size and value.
Definition forward_list.h:1839
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:1887
forward_list_ext(const forward_list_ext &other)
Copy constructor. Implicit pool.
Definition forward_list.h:1848
forward_list_ext(size_t initial_size, etl::ipool &node_pool)
Construct from size.
Definition forward_list.h:1830
forward_list_ext(const forward_list_ext &other, etl::ipool &node_pool)
Copy constructor. Explicit pool.
Definition forward_list.h:1857
~forward_list_ext()
Destructor.
Definition forward_list.h:1907
Definition forward_list.h:1655
~forward_list()
Destructor.
Definition forward_list.h:1733
forward_list(size_t initial_size, const T &value=T())
Construct from size and value.
Definition forward_list.h:1683
forward_list(const forward_list &other)
Copy constructor.
Definition forward_list.h:1692
forward_list()
Default constructor.
Definition forward_list.h:1674
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:1713
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:962
#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:820
reference emplace_front(const T1 &value1)
Emplaces a value to the front of the list..
Definition forward_list.h:750
size_type MAX_SIZE
The maximum size of the forward_list.
Definition forward_list.h:353
void unique(TIsEqual isEqual)
Definition forward_list.h:1182
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:1403
iterator emplace_after(const_iterator position, const T1 &value1)
Emplaces a value to the forward_list after the specified position.
Definition forward_list.h:922
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:780
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:1031
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:1050
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:970
void unique()
Definition forward_list.h:1172
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:986
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:795
void resize(size_t n, T value)
Definition forward_list.h:830
iforward_list(etl::ipool &node_pool, size_t max_size_, bool pool_is_shared_)
Constructor.
Definition forward_list.h:1438
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:906
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:938
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:1133
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:876
reference emplace_front(const T1 &value1, const T2 &value2)
Emplaces a value to the front of the list..
Definition forward_list.h:765
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:954
void sort()
Definition forward_list.h:1213
void sort(TCompare compare)
Definition forward_list.h:1244
void initialise()
Initialise the forward_list.
Definition forward_list.h:1446
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:1381
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:810
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:1009
~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:1069
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:1109
~iforward_list()
Destructor.
Definition forward_list.h:1633
reference emplace_front()
Emplaces a value to the front of the list..
Definition forward_list.h:735
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:1477
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:1430
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:504
void release_all()
Release all objects in the pool.
Definition ipool.h:451
bool full() const
Definition ipool.h:522
size_t max_size() const
Returns the maximum number of items in the pool.
Definition ipool.h:472
void release(const void *const p_object)
Definition ipool.h:442
size_t available() const
Returns the number of free items in the pool.
Definition ipool.h:496
enable_if
Definition type_traits_generator.h:1254
is_integral
Definition type_traits_generator.h:1064
bitset_ext
Definition absolute.h:39
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
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:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:315
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
Definition functional.h:274
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:2237
iterator
Definition iterator.h:399
Definition functional.h:170