ModErn Text Analysis
META Enumerates Textual Applications
comparable.h
Go to the documentation of this file.
1 
12 #ifndef META_COMPARABLE_H_
13 #define META_COMPARABLE_H_
14 
15 #include "meta/config.h"
16 
17 namespace meta
18 {
19 namespace util
20 {
21 
27 template <class Derived>
29 {
30  public:
39  friend constexpr bool operator==(const comparable& lhs,
40  const comparable& rhs)
41  {
42  return !(lhs.as_derived() < rhs.as_derived())
43  && !(rhs.as_derived() < lhs.as_derived());
44  }
45 
54  friend constexpr bool operator!=(const comparable& lhs,
55  const comparable& rhs)
56  {
57  return !(lhs == rhs);
58  }
59 
65  friend constexpr bool operator>(const comparable& lhs,
66  const comparable& rhs)
67  {
68  return rhs.as_derived() < lhs.as_derived();
69  }
70 
77  friend constexpr bool operator<=(const comparable& lhs,
78  const comparable& rhs)
79  {
80  return lhs.as_derived() < rhs.as_derived() || lhs == rhs;
81  }
82 
89  friend constexpr bool operator>=(const comparable& lhs,
90  const comparable& rhs)
91  {
92  return lhs > rhs || lhs == rhs;
93  }
94 
95  private:
102  inline constexpr const Derived& as_derived() const
103  {
104  return static_cast<const Derived&>(*this);
105  }
106 };
107 }
108 }
109 #endif
constexpr const Derived & as_derived() const
Helper method to cast the current comparable to its Derived representation.
Definition: comparable.h:102
friend constexpr bool operator==(const comparable &lhs, const comparable &rhs)
Determines if two comparables are equivalent, as defined by their operator<.
Definition: comparable.h:39
friend constexpr bool operator>(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:65
friend constexpr bool operator!=(const comparable &lhs, const comparable &rhs)
Determines if two comparables are not equivalent, as defined by negation of the comparable::operator=...
Definition: comparable.h:54
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25
A CRTP base class that allows for inheritance of all comparator operators given that the derived clas...
Definition: comparable.h:28
friend constexpr bool operator>=(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:89
friend constexpr bool operator<=(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:77