Re:D 2.069.0 released, compiler automatically ported from C+...
by p0nce on Wednesday November 04, 2015 @03:06PM
(#10509232)
std.typecons.Typedef does something similar: http://dlang.org/phobos/std_typecons.html#.Typedef
There's the 'to' function to perform checked conversions and the standard cast operator to perform unchecked conversions.
int foo = 256; ubyte bar = foo.to!ubyte; // throws ConvException ubyte baz = cast(ubyte) foo; // overflows as expected
If I want more type-safety than this, I'll create simple wrappers:
struct Seconds { int value; alias value this; }
That way I can still pass seconds everywhere an int is expected, but I can now declare arguments to only accept Seconds and not ints.