Can opCmp return a 'long' instead of 'int'?

bearophile bearophileHUGS at lycos.com
Sun Feb 16 07:40:59 PST 2014


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


More information about the Digitalmars-d-learn mailing list