ORIGINAL
Loading...
Searching...
No Matches
comparator.h
Go to the documentation of this file.
1#ifndef COMPARATOR_H
2#define COMPARATOR_H
3
4
17namespace original
18{
19
27 template<typename TYPE>
29 public:
30
34 virtual ~comparator() = default;
35
45 virtual bool compare(const TYPE& t1, const TYPE& t2) const = 0;
46
53 bool operator()(const TYPE& t1, const TYPE& t2) const;
54 };
55
63 template<typename TYPE>
64 class increaseComparator final : public comparator<TYPE> {
65 public:
72 bool compare(const TYPE& t1, const TYPE& t2) const override;
73 };
74
82 template<typename TYPE>
83 class decreaseComparator final : public comparator<TYPE> {
84 public:
91 bool compare(const TYPE& t1, const TYPE& t2) const override;
92 };
93
101 template<typename TYPE>
102 class equalComparator final : public comparator<TYPE> {
103 public:
110 bool compare(const TYPE& t1, const TYPE& t2) const override;
111 };
112
120 template<typename TYPE>
121 class notEqualComparator final : public comparator<TYPE> {
122 public:
129 bool compare(const TYPE& t1, const TYPE& t2) const override;
130 };
131
139 template<typename TYPE>
141 public:
148 bool compare(const TYPE& t1, const TYPE& t2) const override;
149 };
150
158 template<typename TYPE>
160 public:
167 bool compare(const TYPE& t1, const TYPE& t2) const override;
168 };
169}
170
171 template <typename TYPE>
172 auto original::comparator<TYPE>::operator()(const TYPE& t1, const TYPE& t2) const -> bool
173 {
174 return this->compare(t1, t2);
175 }
176
177 template <typename TYPE>
178 auto original::increaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
179 {
180 return t1 < t2;
181 }
182
183 template<typename TYPE>
184 auto original::decreaseComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
185 {
186 return t1 > t2;
187 }
188
189 template <typename TYPE>
190 auto original::equalComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
191 {
192 return t1 == t2;
193 }
194
195 template <typename TYPE>
196 auto original::notEqualComparator<TYPE>::compare(const TYPE& t1, const TYPE& t2) const -> bool
197 {
198 return t1 != t2;
199 }
200
201template<typename TYPE>
203 {
204 return t1 < t2 || t1 == t2;
205 }
206
207
208 template <typename TYPE>
210 {
211 return t1 > t2 || t1 == t2;
212 }
213
214#endif //COMPARATOR_H
Base class for comparison.
Definition comparator.h:28
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:172
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:83
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:184
Comparator for non-strict decreasing comparison (greater than or equal to).
Definition comparator.h:159
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:209
Comparator for equality comparison.
Definition comparator.h:102
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are equal.
Definition comparator.h:190
Comparator for increasing comparison (less than).
Definition comparator.h:64
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:178
Comparator for non-strict increasing comparison (less than or equal to).
Definition comparator.h:140
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:202
Comparator for inequality comparison.
Definition comparator.h:121
bool compare(const TYPE &t1, const TYPE &t2) const override
Compares two elements to check if they are not equal.
Definition comparator.h:196
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Main namespace for the project Original.
Definition algorithms.h:21