summaryrefslogtreecommitdiff
path: root/AK/Concepts.h
blob: 5394fe6ab8bb04cd49fa2eecac03c3a20bf1deaf (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/IterationDecision.h>
#include <AK/StdLibExtras.h>

namespace AK::Concepts {

#if defined(__cpp_concepts) && !defined(__COVERITY__)

template<typename T>
concept Integral = IsIntegral<T>;

template<typename T>
concept FloatingPoint = IsFloatingPoint<T>;

template<typename T>
concept Arithmetic = IsArithmetic<T>;

template<typename T>
concept Signed = IsSigned<T>;

template<typename T>
concept Unsigned = IsUnsigned<T>;

template<typename T, typename U>
concept SameAs = IsSame<T, U>;

template<typename Func, typename... Args>
concept VoidFunction = requires(Func func, Args... args)
{
    {
        func(args...)
    }
    ->SameAs<void>;
};

template<typename Func, typename... Args>
concept IteratorFunction = requires(Func func, Args... args)
{
    {
        func(args...)
    }
    ->SameAs<IterationDecision>;
};

#endif

}

#if defined(__cpp_concepts) && !defined(__COVERITY__)

using AK::Concepts::Arithmetic;
using AK::Concepts::FloatingPoint;
using AK::Concepts::Integral;
using AK::Concepts::IteratorFunction;
using AK::Concepts::Signed;
using AK::Concepts::Unsigned;
using AK::Concepts::VoidFunction;

#endif