libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00036 #ifndef MOOST_UTILS_RELOPS_HPP__ 00037 #define MOOST_UTILS_RELOPS_HPP__ 00038 00039 namespace moost { namespace utils { 00040 00059 template<typename T> 00060 class relops 00061 { 00062 protected: 00063 relops() {} 00064 00065 public: 00076 template <typename U> 00077 bool operator == (U const & rhs) const 00078 { 00079 // I am really a type T 00080 return static_cast<T const *>(this)->operator == (rhs); 00081 } 00082 00083 template <typename U> 00084 friend bool operator == (U const & lhs, T const & rhs) 00085 { 00086 return rhs.operator == (lhs); 00087 } 00088 00099 template <typename U> 00100 bool operator < (U const & rhs) const 00101 { 00102 // I am really a type T 00103 return static_cast<T const *>(this)->operator < (rhs); 00104 } 00105 00106 template <typename U> 00107 friend bool operator < (U const & lhs, T const & rhs) 00108 { 00109 return rhs.operator > (lhs); 00110 } 00111 00123 template <typename U> 00124 bool operator != (U const & rhs) const 00125 { 00126 return !(this->operator == (rhs)); 00127 } 00128 00129 template <typename U> 00130 friend bool operator != (U const & lhs, T const & rhs) 00131 { 00132 return rhs.operator != (lhs); 00133 } 00134 00146 template <typename U> 00147 bool operator > (U const & rhs) const 00148 { 00149 return !(this->operator == (rhs) || this->operator < (rhs)); 00150 } 00151 00152 template <typename U> 00153 friend bool operator > (U const & lhs, T const & rhs) 00154 { 00155 return rhs.operator < (lhs); 00156 } 00157 00169 template <typename U> 00170 bool operator <= (U const & rhs) const 00171 { 00172 return !(this->operator > (rhs)); 00173 } 00174 00175 template <typename U> 00176 friend bool operator <= (U const & lhs, T const & rhs) 00177 { 00178 return rhs.operator >= (lhs); 00179 } 00180 00192 template <typename U> 00193 bool operator >= (U const & rhs) const 00194 { 00195 return !(this->operator < (rhs)); 00196 } 00197 00198 template <typename U> 00199 friend bool operator >= (U const & lhs, T const & rhs) 00200 { 00201 return rhs.operator <= (lhs); 00202 } 00203 }; 00204 00205 }} 00206 00207 #endif