On 12/24/11 9:34 AM, Derek wrote:
Yes, I agree that this is a potential source of bugs. So what we need is
something more explicit.

double foo() { return 1.5; }
void main() {
int x = cast(double:int)foo();
}

Now the code is very clear about your intentions for it, and if foo() is
later modified to return some incompatible datatype, the compile can
alert the coder.

auto explicitCast(From, To)(From value)
{
  return cast(To) value;
}

And to be consistent, we need to have syntax that allows a coder to
explicitly tell the compiler to do a re-interpretation cast.

auto reinterpretCast(From, To)(From value)
if (...)
{
  return cast(To) value;
}

No need for more syntax.


Andrei

Reply via email to