mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
AK: Add const version of Vector::first_matching
This commit is contained in:
parent
ff8ca811c7
commit
7b145d810a
Notes:
sideshowbarker
2024-07-17 14:21:01 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/7b145d810a Pull-request: https://github.com/SerenityOS/serenity/pull/13516 Issue: https://github.com/SerenityOS/serenity/issues/65
11
AK/Vector.h
11
AK/Vector.h
@ -173,6 +173,17 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user