1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

AK: Make Hash{Map,Table}::remove_all_matching() return removal success

These functions now return whether one or more entries were removed.
This commit is contained in:
Andreas Kling 2022-01-05 16:57:45 +01:00
parent c7ac0c2c80
commit 5279a04c78
4 changed files with 24 additions and 12 deletions

View file

@ -419,14 +419,18 @@ public:
}
template<typename TUnaryPredicate>
void remove_all_matching(TUnaryPredicate predicate)
bool remove_all_matching(TUnaryPredicate predicate)
{
bool something_was_removed = false;
for (auto it = begin(); it != end();) {
if (predicate(*it))
if (predicate(*it)) {
it = remove(it);
else
something_was_removed = true;
} else {
++it;
}
}
return something_was_removed;
}
private: