boost::less_than_comparable
继承使用此类可以只重写operator< ,<= ,>会自动生成
头文件:#include <boost/operators.hpp>
实例:
class point :public boost::less_than_comparable<point>
{
public:
point(int num = 0) :num_(num){}
int getNum()const{ return num_; }
private:
int num_;
};
inline bool operator<(point lhs, point rhs)
{
return lhs.getNum() < rhs.getNum();
}
int main()
{
point t1(10);
point t2;
if (t1 < t2)
{
std::cout << "t1 < t2" << std::endl;
}
std::cin.get();
return 1;
}
详细了解 点击打开链接