ORIGINAL
Loading...
Searching...
No Matches
comparable.h
1#ifndef COMPARABLE_H
2#define COMPARABLE_H
3
4namespace original {
5 template <typename DERIVED>
6 class comparable {
7 public:
8 virtual int compareTo(const DERIVED &other) const = 0;
9 bool operator==(const DERIVED &other) const;
10 bool operator!=(const DERIVED &other) const;
11 bool operator<(const DERIVED &other) const;
12 bool operator>(const DERIVED &other) const;
13 bool operator<=(const DERIVED &other) const;
14 bool operator>=(const DERIVED &other) const;
15 virtual ~comparable() = default;
16 };
17
18 template<typename DERIVED>
19 auto comparable<DERIVED>::operator==(const DERIVED &other) const -> bool {
20 return compareTo(other) == 0;
21 }
22
23 template<typename DERIVED>
24 auto comparable<DERIVED>::operator!=(const DERIVED &other) const -> bool {
25 return compareTo(other) != 0;
26 }
27
28 template<typename DERIVED>
29 auto comparable<DERIVED>::operator<(const DERIVED &other) const -> bool {
30 return compareTo(other) < 0;
31 }
32
33 template<typename DERIVED>
34 auto comparable<DERIVED>::operator>(const DERIVED &other) const -> bool {
35 return compareTo(other) > 0;
36 }
37
38 template<typename DERIVED>
39 auto comparable<DERIVED>::operator<=(const DERIVED &other) const -> bool {
40 return compareTo(other) <= 0;
41 }
42
43 template<typename DERIVED>
44 auto comparable<DERIVED>::operator>=(const DERIVED &other) const -> bool {
45 return compareTo(other) >= 0;
46 }
47}
48
49#endif //COMPARABLE_H
Definition comparable.h:6