disabling unary "-" for unsigned types
Michel Fortin
michel.fortin at michelf.com
Mon Feb 15 16:34:57 PST 2010
On 2010-02-15 17:21:09 -0500, Walter Bright <newshound1 at digitalmars.com> said:
> Or:
>
> -cast(int)x
>
> That blows when x happens to be a ulong. Whoops. It blows even worse if
> x turns out to be a struct with overloaded opNeg and opCast, suddenly
> the opCast gets selected. Oops.
That one is easy to fix. Add a "signed(x)" template function returning
the signed counterpart of x. You could even insert a runtime range
check if you really wanted to.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list