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 namespace meta
16 {
17 namespace util
18 {
19 
25 template <class Derived>
27 {
28  public:
37  friend bool operator==(const comparable& lhs, const comparable& rhs)
38  {
39  return !(lhs.as_derived() < rhs.as_derived())
40  && !(rhs.as_derived() < lhs.as_derived());
41  }
42 
51  friend bool operator!=(const comparable& lhs, const comparable& rhs)
52  {
53  return !(lhs == rhs);
54  }
55 
61  friend bool operator>(const comparable& lhs, const comparable& rhs)
62  {
63  return rhs.as_derived() < lhs.as_derived();
64  }
65 
72  friend bool operator<=(const comparable& lhs, const comparable& rhs)
73  {
74  return lhs.as_derived() < rhs.as_derived() || lhs == rhs;
75  }
76 
83  friend bool operator>=(const comparable& lhs, const comparable& rhs)
84  {
85  return lhs > rhs || lhs == rhs;
86  }
87 
88  private:
95  inline const Derived& as_derived() const
96  {
97  return static_cast<const Derived&>(*this);
98  }
99 };
100 }
101 }
102 #endif
friend bool operator>(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:61
const Derived & as_derived() const
Helper method to cast the current comparable to its Derived representation.
Definition: comparable.h:95
friend bool operator==(const comparable &lhs, const comparable &rhs)
Determines if two comparables are equivalent, as defined by their operator<.
Definition: comparable.h:37
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
friend 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:51
friend bool operator<=(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:72
friend bool operator>=(const comparable &lhs, const comparable &rhs)
Definition: comparable.h:83
A CRTP base class that allows for inheritance of all comparator operators given that the derived clas...
Definition: comparable.h:26