C++ boost算子全序由小于可比和等于可比组成
也就是说,完全有序的模板由小于可比模板和tempalte相等可比模板组成 这意味着,如果一个类从完全有序的模板中继承,那么在使用运算符==或运算符!=时必须实现运算符== 在我看来,如果操作符<被实现,那么操作符==可以像(!(lhsC++ boost算子全序由小于可比和等于可比组成,c++,boost,C++,Boost,也就是说,完全有序的模板由小于可比模板和tempalte相等可比模板组成 这意味着,如果一个类从完全有序的模板中继承,那么在使用运算符==或运算符!=时必须实现运算符== 在我看来,如果操作符
#include <boost/operators.hpp>
class Foo : public boost::totally_ordered<Foo>
{
public:
explicit Foo(const int num) : m_nMem(num){}
friend bool operator< (const Foo& lhs, const Foo& rhs)
{
return lhs.m_nMem < rhs.m_nMem;
}
// Is operator== necessary ?
// Is operator== equal to (!(lhs < rhs) && !(rhs < lhs)) ?
//friend bool operator== (const Foo& lhs, const Foo& rhs)
//{
// return lhs.m_nMem == rhs.m_nMem;
//}
private:
int m_nMem;
};
int main()
{
Foo foo_1(1), foo_2(2);
foo_1 == foo_2; // compiler error , no operator==
return 0;
}
#包括
类Foo:public boost::已完全订购
{
公众:
显式Foo(const int num):m_nMem(num){}
friend bool操作员<(恒富和lhs、恒富和rhs)
{
返回lhs.m\u nMem
严格的弱排序可能会将不相等的元素评为等效元素
例如:
结构点{
int x,y;
布尔运算符
struct Point {
int x,y;
bool operator<(Point const& other) const { return x < other.x; }
};