ORIGINAL
Loading...
Searching...
No Matches
comparator.h
Go to the documentation of this file.
1#ifndef COMPARATOR_H
2#define COMPARATOR_H
3
15
16namespace original
17{
18
26 template<typename TYPE>
28 public:
29
33 virtual ~comparator() = default;
34
44 virtual bool compare(const TYPE& t1, const TYPE& t2) const = 0;
45
52 bool operator()(const TYPE& t1, const TYPE& t2) const;
53 };
54
62 template<typename TYPE>
63 class increaseComparator final : public comparator<TYPE> {
64 public:
71 bool compare(const TYPE& t1, const TYPE& t2) const override;
72 };
73
81 template<typename TYPE>
82 class decreaseComparator final : public comparator<TYPE> {
83 public:
90 bool compare(const TYPE& t1, const TYPE& t2) const override;
91 };
92
100 template<typename TYPE>
101 class equalComparator final : public comparator<TYPE> {
102 public:
109 bool compare(const TYPE& t1, const TYPE& t2) const override;
110 };
111
119 template<typename TYPE>
120 class notEqualComparator final : public comparator<TYPE> {
121 public:
128 bool compare(const TYPE& t1, const TYPE& t2) const override;
129 };
130
138 template<typename TYPE>
139 class increaseNotStrictComparator final : public comparator<TYPE> {
140 public:
147 bool compare(const TYPE& t1, const TYPE& t2) const override;
148 };
149
157 template<typename TYPE>
158 class decreaseNotStrictComparator final : public comparator<TYPE> {
159 public:
166 bool compare(const TYPE& t1, const TYPE& t2) const override;
167 };
168}
169
170 template <typename TYPE>
171 auto original::comparator<TYPE>::operator()(const TYPE& t1, const TYPE& t2) const -> bool
172 {
173 return this->compare(t1, t2);
174 }
175
176 template <typename TYPE>
177 auto original::increaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
178 {
179 return t1 < t2;
180 }
181
182 template<typename TYPE>
183 auto original::decreaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
184 {
185 return t1 > t2;
186 }
187
188 template <typename TYPE>
189 auto original::equalComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
190 {
191 return t1 == t2;
192 }
193
194 template <typename TYPE>
195 auto original::notEqualComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
196 {
197 return t1 != t2;
198 }
199
200template<typename TYPE>
201 auto original::increaseNotStrictComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
202 {
203 return t1 < t2 || t1 == t2;
204 }
205
206
207 template <typename TYPE>
208 auto original::decreaseNotStrictComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
209 {
210 return t1 > t2 || t1 == t2;
211 }
212
213#endif //COMPARATOR_H
Base class for comparison.
Definition comparator.h:27
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:171
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:82
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:183
Comparator for non-strict decreasing comparison (greater than or equal to).
Definition comparator.h:158
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:208
Comparator for equality comparison.
Definition comparator.h:101
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are equal.
Definition comparator.h:189
Comparator for increasing comparison (less than).
Definition comparator.h:63
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:177
Comparator for non-strict increasing comparison (less than or equal to).
Definition comparator.h:139
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:201
Comparator for inequality comparison.
Definition comparator.h:120
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are not equal.
Definition comparator.h:195
Main namespace for the project Original.
Definition algorithms.h:21