diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-04-03 18:06:18 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-04 12:48:31 +0200 |
commit | 188207ed79970e5b224f312e2de89d918367d8da (patch) | |
tree | 9a68405289f4f6a97c16d18297fee7aaed8b4fb5 /AK | |
parent | 33e27c545ed7515185ef93ed0c0c0f49e6759e01 (diff) | |
download | serenity-188207ed79970e5b224f312e2de89d918367d8da.zip |
AK: Make Vector<T>::{first,last}_matching() return Optional<T&>
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<T&>, eliminating
the copy and the confusion.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Vector.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 5b7ec2d966..a261ac6241 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -163,7 +163,7 @@ public: VisibleType& last() { return at(size() - 1); } template<typename TUnaryPredicate> - Optional<VisibleType> first_matching(TUnaryPredicate predicate) requires(!contains_reference) + Optional<VisibleType&> 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<typename TUnaryPredicate> - Optional<VisibleType> last_matching(TUnaryPredicate predicate) requires(!contains_reference) + Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference) { for (ssize_t i = size() - 1; i >= 0; --i) { if (predicate(at(i))) { |