What is the preferred method of using std::rel_ops to add the full set of relational operators to a class?
This documentation suggests a
using namespace std::rel_ops
I think that the preferred technique is not to use std::rel_ops
at
all. The technique used in boost::operator
(link) seems to be the usual
solution.
Example:
#include "boost/operators.hpp"
class SomeClass : private boost::equivalent<SomeClass>, boost::totally_ordered<SomeClass>
{
public:
bool operator<(const SomeClass &rhs) const
{
return someNumber < rhs.someNumber;
}
private:
int someNumber;
};
int main()
{
SomeClass a, b;
a < b;
a > b;
a <= b;
a >= b;
a == b;
a != b;
}