mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
AK: Add const version of Vector::first_matching
This commit is contained in:
parent
ff8ca811c7
commit
7b145d810a
1 changed files with 11 additions and 0 deletions
11
AK/Vector.h
11
AK/Vector.h
|
@ -173,6 +173,17 @@ public:
|
||||||
return {};
|
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>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue