mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16: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:
parent
f879e04133
commit
d40d10aae7
4 changed files with 101 additions and 0 deletions
11
AK/AllOf.h
11
AK/AllOf.h
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Iterator.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -24,6 +25,16 @@ constexpr bool all_of(
|
|||
return true;
|
||||
}
|
||||
|
||||
template<IterableContainer Container>
|
||||
constexpr bool all_of(Container&& container, auto const& predicate)
|
||||
{
|
||||
for (auto&& entry : container) {
|
||||
if (!predicate(entry))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::all_of;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue