2020-11-17 04:27:14 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-17 04:27:14 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-22 17:41:00 +03:00
|
|
|
#include <AK/Concepts.h>
|
2021-06-24 19:24:13 +03:00
|
|
|
#include <AK/Find.h>
|
2020-11-23 03:09:44 +03:00
|
|
|
#include <AK/Iterator.h>
|
|
|
|
|
2020-11-17 04:27:14 +03:00
|
|
|
namespace AK {
|
|
|
|
|
2021-07-22 17:49:34 +03:00
|
|
|
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator>
|
2022-06-26 19:18:56 +03:00
|
|
|
[[nodiscard]] constexpr bool all_of(
|
2021-07-22 17:49:34 +03:00
|
|
|
TIterator const& begin,
|
|
|
|
TEndIterator const& end,
|
2021-07-22 17:43:56 +03:00
|
|
|
auto const& predicate)
|
2020-11-17 04:27:14 +03:00
|
|
|
{
|
2021-06-24 19:24:13 +03:00
|
|
|
constexpr auto negated_predicate = [](auto const& pred) {
|
|
|
|
return [&](auto const& elem) { return !pred(elem); };
|
|
|
|
};
|
|
|
|
return !(find_if(begin, end, negated_predicate(predicate)) != end);
|
2020-11-17 04:27:14 +03:00
|
|
|
}
|
|
|
|
|
2021-07-22 17:41:00 +03:00
|
|
|
template<IterableContainer Container>
|
2022-06-26 19:18:56 +03:00
|
|
|
[[nodiscard]] constexpr bool all_of(Container&& container, auto const& predicate)
|
2021-07-22 17:41:00 +03:00
|
|
|
{
|
2021-06-24 19:24:13 +03:00
|
|
|
return all_of(container.begin(), container.end(), predicate);
|
2021-07-22 17:41:00 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 04:27:14 +03:00
|
|
|
}
|
2021-02-17 13:07:01 +03:00
|
|
|
|
|
|
|
using AK::all_of;
|