mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
73fc2b3748
This makes it so these algorithms are usable with arbitrary iterators, as opposed to just instances of AK::SimpleIterator. This commit also makes the requirement of ::index() in find_index() explicit, as previously it was accepting any iterator.
36 lines
688 B
C++
36 lines
688 B
C++
/*
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Concepts.h>
|
|
#include <AK/Find.h>
|
|
#include <AK/Iterator.h>
|
|
|
|
namespace AK {
|
|
|
|
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator>
|
|
constexpr bool any_of(
|
|
TIterator const& begin,
|
|
TEndIterator const& end,
|
|
auto const& predicate)
|
|
{
|
|
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;
|