如果我们想基于一个已经拥有这些运算符的成员来制作一个类的所有关系运算符,那么没有比这更短的方法了吗?
struct foo {
some_class mem; //some_class already has all the relational operators
//other members
}
//is there really no shorter way than to type these 6 functions?
bool operator==(const foo &lhs, const foo &rhs) { return lhs.mem == rhs.mem; }
bool operator!=(const foo &lhs, const foo &rhs) { return lhs.mem != rhs.mem; }
bool operator<(const foo &lhs, const foo &rhs) { return lhs.mem < rhs.mem; }
bool operator>(const foo &lhs, const foo &rhs) { return lhs.mem > rhs.mem; }
bool operator<=(const foo &lhs, const foo &rhs) { return lhs.mem <= rhs.mem; }
bool operator>=(const foo &lhs, const foo &rhs) { return lhs.mem >= rhs.mem; }