From 188207ed79970e5b224f312e2de89d918367d8da Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 3 Apr 2022 18:06:18 +0430 Subject: [PATCH] AK: Make Vector::{first,last}_matching() return Optional These functions are _very_ misleading, as `first()` and `last()` return references, but `{first,last}_matching()` return copies of the values. This commit makes it so that they now return Optional, eliminating the copy and the confusion. --- AK/Vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/Vector.h b/AK/Vector.h index 5b7ec2d9668..a261ac62411 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -163,7 +163,7 @@ public: VisibleType& last() { return at(size() - 1); } template - Optional first_matching(TUnaryPredicate predicate) requires(!contains_reference) + Optional first_matching(TUnaryPredicate predicate) requires(!contains_reference) { for (size_t i = 0; i < size(); ++i) { if (predicate(at(i))) { @@ -174,7 +174,7 @@ public: } template - Optional last_matching(TUnaryPredicate predicate) requires(!contains_reference) + Optional last_matching(TUnaryPredicate predicate) requires(!contains_reference) { for (ssize_t i = size() - 1; i >= 0; --i) { if (predicate(at(i))) {