mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:07:34 +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
1 changed files with 11 additions and 0 deletions
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)
|
void unchecked_append(T&& value)
|
||||||
{
|
{
|
||||||
ASSERT((size() + 1) <= capacity());
|
ASSERT((size() + 1) <= capacity());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue