fennec
Loading...
Searching...
No Matches
compare.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_COMPARE_H
20#define FENNEC_LANG_COMPARE_H
21
22#include <fennec/lang/type_operators.h>
23
24namespace fennec
25{
26
27// equality ============================================================================================================
28
29template<typename T0, typename T1 = T0> struct equality;
30
31template<typename T0, typename T1> requires has_equals_v<T0, T1>
32struct equality<T0, T1> {
33 constexpr bool operator()(const T0& x, const T1& y) const {
34 return x == y;
35 }
36};
37
38template<typename T0, typename T1> requires(not has_equals_v<T0, T1>
39 and has_less_v<T0, T1> and has_less_v<T1, T0>)
40struct equality<T0, T1> {
41 constexpr bool operator()(const T0& x, const T1& y) const {
42 return not(x < y) and not(y < x);
43 }
44};
45
46template<typename T0, typename T1> requires(not(has_equals_v<T0, T1>)
47 and(not has_less_v<T0, T1> or not has_less_v<T1, T0>)
48 and(has_greater_v<T0, T1> and has_greater_v<T1, T0>))
49struct equality<T0, T1> {
50 constexpr bool operator()(const T0& x, const T1& y) const {
51 return not(x > y) and not(y > x);
52 }
53};
54
55
56// inequality ==========================================================================================================
57
58template<typename T0, typename T1 = T0> struct inequality;
59
60template<typename T0, typename T1> requires has_nequals_v<T0, T1>
61struct inequality<T0, T1> {
62 constexpr bool operator()(const T0& x, const T1& y) const {
63 return x != y;
64 }
65};
66
67template<typename T0, typename T1> requires has_less_v<T0, T1> and has_less_v<T1, T0>
68struct inequality<T0, T1> {
69 constexpr bool operator()(const T0& x, const T1& y) const {
70 return (x < y) or (y < x);
71 }
72};
73
74template<typename T0, typename T1> requires has_greater_v<T0, T1> and has_greater_v<T1, T0>
75struct inequality<T0, T1> {
76 constexpr bool operator()(const T0& x, const T1& y) const {
77 return (x > y) or (y > x);
78 }
79};
80
81
82// less ================================================================================================================
83
84template<typename T0, typename T1 = T0> requires has_less_v<T0, T1>
85struct less {
86 constexpr bool operator()(const T0& x, const T1& y) const {
87 return x < y;
88 }
89};
90
91
92// less_equal ==========================================================================================================
93
94template<typename T0, typename T1 = T0> requires has_less_equals_v<T0, T1>
95struct less_equals {
96 constexpr bool operator()(const T0& x, const T1& y) const {
97 return x <= y;
98 }
99};
100
101
102// less ================================================================================================================
103
104template<typename T0, typename T1 = T0> requires has_greater_v<T0, T1>
105struct greater {
106 constexpr bool operator()(const T0& x, const T1& y) const {
107 return x < y;
108 }
109};
110
111
112// less_equal ==========================================================================================================
113
114template<typename T0, typename T1 = T0> requires has_greater_equals_v<T0, T1>
115struct greater_equals {
116 constexpr bool operator()(const T0& x, const T1& y) const {
117 return x <= y;
118 }
119};
120
121}
122
123#endif // FENNEC_LANG_COMPARE_H
constexpr genType y()
Definition constants.h:672