Return count from nano::erase_if (...)

This commit is contained in:
Piotr Wójcik 2025-02-12 21:50:14 +01:00
commit edc61e1a53

View file

@ -47,19 +47,22 @@ void transform_if (InputIt first, InputIt last, OutputIt dest, Pred pred, Func t
* TODO: Use `std::erase_if` in c++20 * TODO: Use `std::erase_if` in c++20
*/ */
template <class Container, class Pred> template <class Container, class Pred>
void erase_if (Container & container, Pred pred) size_t erase_if (Container & container, Pred pred)
{ {
size_t result = 0;
for (auto it = container.begin (), end = container.end (); it != end;) for (auto it = container.begin (), end = container.end (); it != end;)
{ {
if (pred (*it)) if (pred (*it))
{ {
it = container.erase (it); it = container.erase (it);
++result;
} }
else else
{ {
++it; ++it;
} }
} }
return result;
} }
/** Safe narrowing cast which silences warnings and asserts on data loss in debug builds. This is optimized away. */ /** Safe narrowing cast which silences warnings and asserts on data loss in debug builds. This is optimized away. */