fennec
Loading...
Searching...
No Matches
type_operators.h
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef FENNEC_LANG_TYPE_OPERATORS_H
20#define FENNEC_LANG_TYPE_OPERATORS_H
21
22namespace fennec
23{
24
25// https://stackoverflow.com/questions/6534041/how-to-check-whether-operator-exists
26
27// has_equals ==========================================================================================================
28
29template<typename T0, typename T1 = T0>
30struct has_equals {
31 // Use SFINAE to check for the operator
32 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() == declval<V>());
33 template<typename, typename> static auto test(...) -> false_type;
34
35 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
36};
37
38template<typename T0, typename T1 = T0> constexpr bool has_equals_v = has_equals<T0, T1>::value;
39
40// has_nequals =========================================================================================================
41
42template<typename T0, typename T1 = T0>
43struct has_nequals {
44 // Use SFINAE to check for the operator
45 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() != declval<V>());
46 template<typename, typename> static auto test(...) -> false_type;
47
48 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
49};
50
51template<typename T0, typename T1 = T0> constexpr bool has_nequals_v = has_nequals<T0, T1>::value;
52
53
54// has_less ============================================================================================================
55
56template<typename T0, typename T1 = T0>
57struct has_less {
58 // Use SFINAE to check for the operator
59 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() < declval<V>());
60 template<typename, typename> static auto test(...) -> false_type;
61
62 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
63};
64
65template<typename T0, typename T1 = T0> constexpr bool has_less_v = has_less<T0, T1>::value;
66
67
68// has_less_equals =====================================================================================================
69
70template<typename T0, typename T1 = T0>
71struct has_less_equals {
72 // Use SFINAE to check for the operator
73 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() <= declval<V>());
74 template<typename, typename> static auto test(...) -> false_type;
75
76 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
77};
78
79template<typename T0, typename T1 = T0> constexpr bool has_less_equals_v = has_less_equals<T0, T1>::value;
80
81
82// has_greater =========================================================================================================
83
84template<typename T0, typename T1 = T0>
85struct has_greater {
86 // Use SFINAE to check for the operator
87 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() > declval<V>());
88 template<typename, typename> static auto test(...) -> false_type;
89
90 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
91};
92
93template<typename T0, typename T1 = T0> constexpr bool has_greater_v = has_greater<T0, T1>::value;
94
95
96// has_greater_equals ==================================================================================================
97
98template<typename T0, typename T1 = T0>
99struct has_greater_equals {
100 // Use SFINAE to check for the operator
101 template<typename U, typename V> static auto test(U*) -> decltype(declval<U>() >= declval<V>());
102 template<typename, typename> static auto test(...) -> false_type;
103
104 static constexpr bool value = is_same_v<bool, decltype(test<T0, T1>(0))>;
105};
106
107template<typename T0, typename T1 = T0> constexpr bool has_greater_equals_v = has_greater_equals<T0, T1>::value;
108
109
110}
111
112#endif // FENNEC_LANG_TYPE_OPERATORS_H