如果结构具有任意多个数据成员(<将使用列出数据成员的顺序定义),如何概括<的定义?一个包含 3 个数据成员的简单示例:
struct nData {
int a;
double b;
CustomClass c; // with == and < defined for CustomClass
bool operator == (const nData& other) {return (a == other.a) && (b == other.b) && (c == other.c);}
bool operator < (const nData& other) {
if ( (a < other.a) || ((a == other.a) && (b < other.b)) ||
((a == other.a) && (b == other.b) && (c < other.c)) )
return true;
return false;
}
};
以某种方式使用可变参数模板和递归?