From edc61e1a53cd6fe7258e78a410f107b5d5ed6248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 12 Feb 2025 21:50:14 +0100 Subject: [PATCH] Return count from `nano::erase_if (...)` --- nano/lib/utility.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nano/lib/utility.hpp b/nano/lib/utility.hpp index ef31b01e3..f86e71a2e 100644 --- a/nano/lib/utility.hpp +++ b/nano/lib/utility.hpp @@ -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 */ template -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;) { if (pred (*it)) { it = container.erase (it); + ++result; } else { ++it; } } + return result; } /** Safe narrowing cast which silences warnings and asserts on data loss in debug builds. This is optimized away. */