mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03: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
Notes:
sideshowbarker
2024-07-19 15:00:50 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/214b67defd8
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 New Issue
Block a user