mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Improved erase_after
This commit is contained in:
parent
6c4a29b498
commit
0f05e7d4be
@ -527,7 +527,6 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases the value at the specified position.
|
||||
/// Clears the link after erasing if CHECKED.
|
||||
//*************************************************************************
|
||||
iterator erase_after(iterator position)
|
||||
{
|
||||
@ -544,36 +543,32 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a range of elements.
|
||||
/// Clears the links after erasing if CHECKED.
|
||||
//*************************************************************************
|
||||
iterator erase_after(iterator first, iterator last)
|
||||
{
|
||||
link_type* p_first = first.p_value;
|
||||
link_type* p_last = last.p_value;
|
||||
link_type* p_next = p_first->etl_next;
|
||||
|
||||
// Join the ends.
|
||||
etl::link<link_type>(p_first, p_last);
|
||||
|
||||
p_first = p_next;
|
||||
|
||||
// Erase the ones in between.
|
||||
while (p_first != p_last)
|
||||
if (first != last)
|
||||
{
|
||||
// One less.
|
||||
--current_size;
|
||||
current_size -= std::distance(first, last) - 1;
|
||||
|
||||
p_next = p_first->etl_next; // Remember the next link.
|
||||
p_first = p_next; // Move to the next link.
|
||||
}
|
||||
link_type* p_first = first.p_value;
|
||||
link_type* p_last = last.p_value;
|
||||
link_type* p_next = p_first->etl_next;
|
||||
|
||||
if (p_next == nullptr)
|
||||
{
|
||||
return end();
|
||||
// Join the ends.
|
||||
etl::link<link_type>(p_first, p_last);
|
||||
|
||||
if (p_next == nullptr)
|
||||
{
|
||||
return end();
|
||||
}
|
||||
else
|
||||
{
|
||||
return last;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return iterator(*static_cast<value_type*>(p_last));
|
||||
return last;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user