diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-22 18:29:12 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-22 18:29:12 +0100 |
commit | 11d49aedd87bcc522c0de0bbe3b5a44a7b3e3151 (patch) | |
tree | 4729f64c463cdadad6d59278ab2302badc0efd1a | |
parent | 9e3e13e4108e953826a7c3f9286daadba04be334 (diff) | |
download | serenity-11d49aedd87bcc522c0de0bbe3b5a44a7b3e3151.zip |
AK: Add Vector::remove_all_matching()
-rw-r--r-- | AK/Vector.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 2e3a13e69e..daf3cd0a55 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -360,6 +360,18 @@ public: } } + template<typename Callback> + void remove_all_matching(Callback callback) + { + for (int i = 0; i < size();) { + if (callback(at(i))) { + remove(i); + } else { + ++i; + } + } + } + void unchecked_append(T&& value) { ASSERT((size() + 1) <= capacity()); @@ -535,6 +547,7 @@ public: } return -1; } + private: void reset_capacity() { |