mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00: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
1 changed files with 11 additions and 0 deletions
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…
Add table
Reference in a new issue