https://issues.dlang.org/show_bug.cgi?id=259

--- Comment #63 from Dominikus Dittes Scherkl <[email protected]> ---
(In reply to Dominikus Dittes Scherkl from comment #58)
> So why don't we change to something that simply always works?

I have meanwhile improved my solution to something more straight forward, with
less superfluous casting, and now that the frontend is written in D, it should
be no problem to integrate it in the compiler:

int opCmp(T, U)(const(T) a, const(U) b) pure @safe @nogc nothrow
   if(isIntegral!T && isIntegral!U && is(Unqual!T != Unqual!U))
{
   static if(isSigned!T && isUnsigned!U && T.sizeof <= U.sizeof)
      return (a < 0) ? -1 : opCmp(cast(U)a, b);
   else static if(isUnsigned!T && isSigned!U && T.sizeof >= U.sizeof)
      return (b < 0) ? 1 : opCmp(a, cast(T)b);
   else // do interger propagation as ever:
      return opCmp(cast(CommonType!(T, U))a, cast(CommonType!(T, U))b);
}

--

Reply via email to