mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
d40d10aae7
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).
36 lines
714 B
C++
36 lines
714 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 Container, typename ValueType>
|
|
constexpr bool any_of(
|
|
const SimpleIterator<Container, ValueType>& begin,
|
|
const SimpleIterator<Container, ValueType>& end,
|
|
const auto& 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;
|