1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

AK: Implement {any,all}_of(IterableContainer&&, Predicate)

This is a generally nicer-to-use version of the existing {any,all}_of()
that doesn't require the user to explicitly provide two iterators.
As a bonus, it also allows arbitrary iterators (as opposed to the hard
requirement of providing SimpleIterators in the iterator version).
This commit is contained in:
Ali Mohammad Pur 2021-07-22 19:11:00 +04:30 committed by Andreas Kling
parent f879e04133
commit d40d10aae7
4 changed files with 101 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/Concepts.h>
#include <AK/Find.h>
#include <AK/Iterator.h>
@ -20,6 +21,16 @@ constexpr bool any_of(
return find_if(begin, end, predicate) != end;
}
template<IterableContainer Container>
constexpr bool any_of(Container&& container, auto const& predicate)
{
for (auto&& entry : container) {
if (predicate(entry))
return true;
}
return false;
}
}
using AK::any_of;