mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
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.
This commit is contained in:
parent
33e27c545e
commit
188207ed79
Notes:
sideshowbarker
2024-07-17 14:28:06 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/188207ed79 Pull-request: https://github.com/SerenityOS/serenity/pull/13470 Reviewed-by: https://github.com/BenWiederhake ✅ Reviewed-by: https://github.com/creator1creeper1 Reviewed-by: https://github.com/sin-ack ✅
1 changed files with 2 additions and 2 deletions
|
@ -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))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue