mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +08:00
Added variadic constructors
This commit is contained in:
parent
e103d0959f
commit
8890f43918
@ -338,20 +338,24 @@ namespace etl
|
||||
/// Tests if the link is in this list.
|
||||
/// Returns the previous link to it, if found, otherwise ETL_NULLPTR.
|
||||
//*************************************************************************
|
||||
link_type* is_link_in_list(const link_type* search_link)
|
||||
link_type* is_link_in_list(link_type& search_link)
|
||||
{
|
||||
link_type* p_link = start.etl_next;
|
||||
link_type* p_previous = &start;
|
||||
|
||||
while (p_link != ETL_NULLPTR)
|
||||
{
|
||||
if (search_link == p_link)
|
||||
if (&search_link == p_link)
|
||||
{
|
||||
return p_previous;
|
||||
}
|
||||
|
||||
p_previous = p_link;
|
||||
p_link = p_link->link_type::etl_next;
|
||||
|
||||
if (p_link != ETL_NULLPTR)
|
||||
{
|
||||
p_link = p_link->link_type::etl_next;
|
||||
}
|
||||
}
|
||||
|
||||
return ETL_NULLPTR;
|
||||
@ -362,7 +366,7 @@ namespace etl
|
||||
/// Returns ETL_NULLPTR if the link was not in this list.
|
||||
/// Returns the next
|
||||
//*************************************************************************
|
||||
link_type* remove_link(link_type* link)
|
||||
link_type* remove_link(link_type& link)
|
||||
{
|
||||
link_type* result = ETL_NULLPTR;
|
||||
|
||||
@ -370,7 +374,7 @@ namespace etl
|
||||
|
||||
if (p_previous != ETL_NULLPTR)
|
||||
{
|
||||
link_type* p_next = link->etl_next;
|
||||
link_type* p_next = link.etl_next;
|
||||
|
||||
disconnect_link_after(*p_previous);
|
||||
|
||||
@ -632,11 +636,9 @@ namespace etl
|
||||
template <typename... TLinks>
|
||||
intrusive_forward_list(link_type& first, TLinks&... links)
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_base_of_all<link_type, TLinks...>::value), "Mixed link types");
|
||||
|
||||
this->current_size = 0;
|
||||
current_size = 0;
|
||||
this->start.etl_next = &first;
|
||||
link_type* last = make_linked_list(this->current_size, first, static_cast<link_type&>(links)...);
|
||||
link_type* last = make_linked_list(current_size, first, static_cast<link_type&>(links)...);
|
||||
last->etl_next = &this->terminator;
|
||||
}
|
||||
#endif
|
||||
@ -799,17 +801,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Erases the specified node.
|
||||
//*************************************************************************
|
||||
node_type* erase(const node_type& node)
|
||||
node_type* erase(node_type& node)
|
||||
{
|
||||
return static_cast<node_type*>(this->remove_link(const_cast<node_type*>(&node)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases the specified node.
|
||||
//*************************************************************************
|
||||
node_type* erase(const node_type* p_node)
|
||||
{
|
||||
return static_cast<node_type*>(this->remove_link(const_cast<node_type*>(p_node)));
|
||||
return static_cast<node_type*>(this->remove_link(node));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1011,29 +1005,6 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Removes the element specified by pointer.
|
||||
//*************************************************************************
|
||||
void remove(const_pointer element)
|
||||
{
|
||||
iterator i_item = begin();
|
||||
iterator i_last_item = before_begin();
|
||||
|
||||
while (i_item != end())
|
||||
{
|
||||
if (&i_item == element)
|
||||
{
|
||||
i_item = erase_after(i_last_item);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i_item;
|
||||
++i_last_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Removes according to a predicate.
|
||||
//*************************************************************************
|
||||
@ -1216,10 +1187,10 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Create a linked list from a number of forward_link nodes.
|
||||
//***************************************************************************
|
||||
template <typename... TLinks>
|
||||
link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links)
|
||||
template <typename TLink, typename... TLinks>
|
||||
TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links)
|
||||
{
|
||||
link_type* current = &first;
|
||||
TLink* current = &first;
|
||||
++count;
|
||||
((current->etl_next = &links, current = &links, ++count), ...);
|
||||
|
||||
|
||||
@ -379,13 +379,13 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Tests if the link is in this list.
|
||||
//*************************************************************************
|
||||
bool is_link_in_list(const link_type* search_link) const
|
||||
bool is_link_in_list(link_type& search_link) const
|
||||
{
|
||||
link_type* p_link = terminal_link.link_type::etl_next;
|
||||
|
||||
while (p_link != &terminal_link)
|
||||
{
|
||||
if (search_link == p_link)
|
||||
if (&search_link == p_link)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -400,13 +400,13 @@ namespace etl
|
||||
/// Remove the specified node from the list.
|
||||
/// Returns ETL_NULLPTR if the link was not in this list or was the last in the list.
|
||||
//*************************************************************************
|
||||
link_type* remove_link(link_type* link)
|
||||
link_type* remove_link(link_type& link)
|
||||
{
|
||||
link_type* result = ETL_NULLPTR;
|
||||
|
||||
if (is_link_in_list(link))
|
||||
{
|
||||
link_type* p_next = link->etl_next;
|
||||
link_type* p_next = link.etl_next;
|
||||
|
||||
disconnect_link(link);
|
||||
|
||||
@ -692,11 +692,9 @@ namespace etl
|
||||
template <typename... TLinks>
|
||||
intrusive_list(link_type& first, TLinks&... links)
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_base_of_all<link_type, TLinks...>::value), "Mixed link types");
|
||||
|
||||
this->current_size = 0;
|
||||
current_size = 0;
|
||||
this->terminal_link.etl_next = &first;
|
||||
link_type* last = make_linked_list(this->current_size, first, static_cast<link_type&>(links)...);
|
||||
link_type* last = make_linked_list(current_size, first, static_cast<link_type&>(links)...);
|
||||
first.etl_previous = &this->terminal_link;
|
||||
last->etl_next = &this->terminal_link;
|
||||
this->terminal_link.etl_previous = last;
|
||||
@ -861,17 +859,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Erases the specified node.
|
||||
//*************************************************************************
|
||||
node_type* erase(const node_type& node)
|
||||
node_type* erase(node_type& node)
|
||||
{
|
||||
return static_cast<node_type*>(this->remove_link(const_cast<node_type*>(&node)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases the specified node.
|
||||
//*************************************************************************
|
||||
node_type* erase(const node_type* p_node)
|
||||
{
|
||||
return static_cast<node_type*>(this->remove_link(const_cast<node_type*>(p_node)));
|
||||
return static_cast<node_type*>(this->remove_link(node));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user