So at all the implementation will look something like this:

int opCmp(T, U)(const(T) a, const(U) b) @primitive if(isIntegral!T && isIntegral!U)
{
   alias CommonType!(Signed!T, Signed!U) C;

   static if(isSigned!T && isUnsigned!U)
   {
return (b > cast(Unsigned!C)C.max) ? -1 : cast(C)a - cast(C)b;
   }
   else static if(isUnsigned!T && isSigned!U)
   {
return (a > cast(Unsigned!C)C.max) ? 1 : cast(C)a - cast(C)b;
   }
   else // both signed or both unsigned
   {
      return cast(C)a - cast(C)b;
   }
}

And it will be just as fast as ever, except if you compare apples with peaches where it take a tick longer but give the correct result anyway

Reply via email to