summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-04-04 18:26:00 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-06 12:47:50 +0200
commit7b145d810a6a6f093116e35c878458b8a78485df (patch)
tree54502d3e9ce2bf7ec5400c6f140ebab43d7e8b94
parentff8ca811c786e23d0c35408f911dc13aab5f5cfa (diff)
downloadserenity-7b145d810a6a6f093116e35c878458b8a78485df.zip
AK: Add const version of Vector::first_matching
-rw-r--r--AK/Vector.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h
index a261ac6241..88c0ba74c2 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -174,6 +174,17 @@ public:
}
template<typename TUnaryPredicate>
+ Optional<VisibleType const&> first_matching(TUnaryPredicate predicate) const requires(!contains_reference)
+ {
+ for (size_t i = 0; i < size(); ++i) {
+ if (predicate(at(i))) {
+ return Optional<VisibleType const&>(at(i));
+ }
+ }
+ return {};
+ }
+
+ template<typename TUnaryPredicate>
Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
{
for (ssize_t i = size() - 1; i >= 0; --i) {