mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
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:
parent
d7659ceebf
commit
214b67defd
11
AK/Vector.h
11
AK/Vector.h
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue