From 214b67defd806846d9b1db35061ee0ed7e5263ef Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Mar 2019 20:50:39 +0100 Subject: [PATCH] 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. --- AK/Vector.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index 896ffa16f46..aa26b3b2dce 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -184,6 +184,17 @@ public: } } + template + 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());