2020-11-17 01:27:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-17 01:27:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-22 14:41:00 +00:00
|
|
|
#include <AK/Concepts.h>
|
2020-11-23 00:09:44 +00:00
|
|
|
#include <AK/Iterator.h>
|
|
|
|
|
2020-11-17 01:27:14 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2021-07-22 14:49:34 +00:00
|
|
|
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator>
|
2020-11-23 00:09:44 +00:00
|
|
|
constexpr bool all_of(
|
2021-07-22 14:49:34 +00:00
|
|
|
TIterator const& begin,
|
|
|
|
TEndIterator const& end,
|
2021-07-22 14:43:56 +00:00
|
|
|
auto const& predicate)
|
2020-11-17 01:27:14 +00:00
|
|
|
{
|
|
|
|
for (auto iter = begin; iter != end; ++iter) {
|
|
|
|
if (!predicate(*iter)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-22 14:41:00 +00:00
|
|
|
template<IterableContainer Container>
|
|
|
|
constexpr bool all_of(Container&& container, auto const& predicate)
|
|
|
|
{
|
|
|
|
for (auto&& entry : container) {
|
|
|
|
if (!predicate(entry))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-17 01:27:14 +00:00
|
|
|
}
|
2021-02-17 10:07:01 +00:00
|
|
|
|
|
|
|
using AK::all_of;
|