Timon Gehr:
assert(S(1)<S(2)); // passes. ok.
assert(S(int.min)>S(int.max)); // passes. oops.
A possible solution is to add to Phobos (unless it's already there) a variadic templated funcion cmpBuilder() that accepts an even number of arguments, that are seen as pairs. Usage example:
struct Foo {
int x, y;
string s;
int opCmp(in ref Foo r) {
return cmpBuilder(x, r.x, y.abs, r.y.abs, s, r.s);
}
}
Is this worth adding to Phobos?
Bye,
bearophile
