tuple
is a good idea, but if you want to keep having names for your member variables, it might be good enough to restructure your comparison function like this:
struct MyData {
string surname;
string forename;
string var;
// ...
bool operator<(const MyData& other) const {
if (surname != other.surname) return surname < other.surname;
if (forename != other.forename) return forename < other.forename;
if (var != other.var) return var < other.var;
// ...
return false; //< They are equal
}
};
Depending on your taste, you might even want a macro like #define COMPARE(field) if (field != other.field) return field < other.field;
to reduce duplication. Then the function would just become a list of COMPARE
-invocations.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…