ORIGINAL
Loading...
Searching...
No Matches
comparator.h
Go to the documentation of this file.
1#ifndef COMPARATOR_H
2#define COMPARATOR_H
3
4#include "types.h"
5
17
18namespace original
19{
20
28 template<typename TYPE>
30 public:
31
35 virtual ~comparator() = default;
36
46 virtual bool compare(const TYPE& t1, const TYPE& t2) const = 0;
47
54 bool operator()(const TYPE& t1, const TYPE& t2) const;
55 };
56
64 template<typename TYPE>
65 class increaseComparator final : public comparator<TYPE> {
66 public:
73 bool compare(const TYPE& t1, const TYPE& t2) const override;
74 };
75
83 template<typename TYPE>
84 class decreaseComparator final : public comparator<TYPE> {
85 public:
92 bool compare(const TYPE& t1, const TYPE& t2) const override;
93 };
94
102 template<typename TYPE>
103 class equalComparator final : public comparator<TYPE> {
104 public:
111 bool compare(const TYPE& t1, const TYPE& t2) const override;
112 };
113
121 template<typename TYPE>
122 class notEqualComparator final : public comparator<TYPE> {
123 public:
130 bool compare(const TYPE& t1, const TYPE& t2) const override;
131 };
132
140 template<typename TYPE>
141 class increaseNotStrictComparator final : public comparator<TYPE> {
142 public:
149 bool compare(const TYPE& t1, const TYPE& t2) const override;
150 };
151
159 template<typename TYPE>
160 class decreaseNotStrictComparator final : public comparator<TYPE> {
161 public:
168 bool compare(const TYPE& t1, const TYPE& t2) const override;
169 };
170}
171
172 template <typename TYPE>
173 auto original::comparator<TYPE>::operator()(const TYPE& t1, const TYPE& t2) const -> bool
174 {
175 return this->compare(t1, t2);
176 }
177
178 template <typename TYPE>
179 auto original::increaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
180 {
181 return t1 < t2;
182 }
183
184 template<typename TYPE>
185 auto original::decreaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
186 {
187 return t1 > t2;
188 }
189
190 template <typename TYPE>
191 auto original::equalComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
192 {
193 return t1 == t2;
194 }
195
196 template <typename TYPE>
197 auto original::notEqualComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
198 {
199 return t1 != t2;
200 }
201
202template<typename TYPE>
203 auto original::increaseNotStrictComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
204 {
205 return t1 < t2 || t1 == t2;
206 }
207
208
209 template <typename TYPE>
210 auto original::decreaseNotStrictComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
211 {
212 return t1 > t2 || t1 == t2;
213 }
214
215#endif //COMPARATOR_H
Base class for comparison.
Definition comparator.h:29
virtual ~comparator()=default
Virtual destructor for the comparator class.
bool operator()(const TYPE &t1, const TYPE &t2) const
Function call operator for comparing two elements using the compare method.
Definition comparator.h:173
virtual bool compare(const TYPE &t1, const TYPE &t2) const =0
Pure virtual compare method for comparing two elements.
Comparator for decreasing comparison (greater than).
Definition comparator.h:84
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if the first is greater than the second.
Definition comparator.h:185
Comparator for non-strict decreasing comparison (greater than or equal to).
Definition comparator.h:160
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if the first is greater than or equal to the second.
Definition comparator.h:210
Comparator for equality comparison.
Definition comparator.h:103
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are equal.
Definition comparator.h:191
Comparator for increasing comparison (less than).
Definition comparator.h:65
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if the first is less than the second.
Definition comparator.h:179
Comparator for non-strict increasing comparison (less than or equal to).
Definition comparator.h:141
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if the first is less than or equal to the second.
Definition comparator.h:203
Comparator for inequality comparison.
Definition comparator.h:122
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are not equal.
Definition comparator.h:197
Main namespace for the project Original.
Definition algorithms.h:21
Type system foundations and concept definitions.