summaryrefslogtreecommitdiff
path: root/AK/GenericShorthands.h
blob: 73941857dfb522d6a3deff28c7cbe5fe20868615 (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
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (c) 2022, Frhun <serenitystuff@frhun.de>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Platform.h>

namespace AK {

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_one_of(T const to_compare, Ts const... valid_values)
{
    return (... || (to_compare == valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_smaller_than_one_of(T const to_compare, Ts const... valid_values)
{
    return (... || (to_compare < valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_smaller_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
{
    return (... || (to_compare <= valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_larger_than_one_of(T const to_compare, Ts const... valid_values)
{
    return (... || (to_compare > valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_larger_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
{
    return (... || (to_compare >= valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_smaller_than_all_of(T const to_compare, Ts const... valid_values)
{
    return (... && (to_compare < valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_smaller_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
{
    return (... && (to_compare <= valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_larger_than_all_of(T const to_compare, Ts const... valid_values)
{
    return (... && (to_compare > valid_values));
}

template<typename T, typename... Ts>
[[nodiscard]] bool first_is_larger_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
{
    return (... && (to_compare >= valid_values));
}
}

#if USING_AK_GLOBALLY
using AK::first_is_larger_or_equal_than_all_of;
using AK::first_is_larger_or_equal_than_one_of;
using AK::first_is_larger_than_all_of;
using AK::first_is_larger_than_one_of;
using AK::first_is_one_of;
using AK::first_is_smaller_or_equal_than_all_of;
using AK::first_is_smaller_or_equal_than_one_of;
using AK::first_is_smaller_than_all_of;
using AK::first_is_smaller_than_one_of;
#endif