On Sun, 18 Mar 2012 15:53:56 -0400, Andrej Mitrovic <[email protected]> wrote:

On 3/18/12, Manu <[email protected]> wrote:
I'm finding that in this code I'm writing, casts are taking up more space
on many lines than the actual term being assigned.

Another classic which fails to compile is:

import std.random;
ubyte c = uniform(0, 256);

In the call uniform returns a number anywhere from 0 to and including
255, which can fit perfectly in a ubyte. But I have to use a cast
(which is error-prone if I change the right interval), or use a
to!ubyte call (which is verbose). Granted for simple-purpose random
number generation a cast might be safe..

What if you don't have std.random's source, all you (the compiler) have is the function signature?

BTW, you can use this instead of a cast:

ubyte c = uniform(0, 256) & 0xff;

-Steve

Reply via email to