AK: Add Vector::remove_first_matching(Callback).

This is a nice little helper to remove one item based on a matching
callback without having to do iteration yourself.
This commit is contained in:
Andreas Kling 2019-03-18 20:50:39 +01:00
parent d7659ceebf
commit 214b67defd

View file

@ -184,6 +184,17 @@ public:
}
}
template<typename Callback>
void remove_first_matching(Callback callback)
{
for (int i = 0; i < size(); ++i) {
if (callback(at(i))) {
remove(i);
return;
}
}
}
void unchecked_append(T&& value)
{
ASSERT((size() + 1) <= capacity());