#815 etl::remove_if calls predicate twice for first iterator, where predicate returns true.

This commit is contained in:
John Wellbelove 2024-04-23 09:54:53 +01:00
parent c100cb1b88
commit 3f9b990a72

View File

@ -2022,19 +2022,18 @@ namespace etl
ETL_CONSTEXPR14
TIterator remove(TIterator first, TIterator last, const T& value)
{
first = etl::find(first, last, value);
if (first != last)
{
TIterator itr = first;
while (itr != last)
while (++itr != last)
{
if (!(*itr == value))
{
*first = etl::move(*itr);
++first;
*first++ = etl::move(*itr);
}
++itr;
}
}
@ -2049,23 +2048,22 @@ namespace etl
ETL_CONSTEXPR14
TIterator remove_if(TIterator first, TIterator last, TUnaryPredicate predicate)
{
first = etl::find_if(first, last, predicate);
if (first != last)
{
TIterator itr = first;
while (itr != last)
while (++itr != last)
{
if (!predicate(*itr))
{
*first = etl::move(*itr);
++first;
*first++ = etl::move(*itr);
}
++itr;
}
}
return first;
return first;
}
}