summaryrefslogtreecommitdiff
path: root/AK/AllOf.h
blob: a551046b97704698e9a812001e5fbfe807cb35cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Concepts.h>
#include <AK/Iterator.h>

namespace AK {

template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator>
constexpr bool all_of(
    TIterator const& begin,
    TEndIterator const& end,
    auto const& predicate)
{
    for (auto iter = begin; iter != end; ++iter) {
        if (!predicate(*iter)) {
            return false;
        }
    }
    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;