Casting away const and invariant

Daniel Keep daniel.keep.lists at gmail.com
Sun Sep 9 17:54:03 PDT 2007



Janice Caron wrote:
>> D's single cast syntax is rather a step backwards from C++.
> 
> D's single cast syntax dates from a time before there was const. If
> there's no const, you don't need a const_cast. Only with the advent of
> const in 2.0 do we start to encounter problems.

Actually, there's one other deficiency in only having a single cast that
trips up newbies from time to time:

Why does cast(int) 42.31 == 42, but cast(int[]) [42.31] fail?

Because one is doing a *cast* and the other is doing a *conversion.*
Once you involve things like opCast and opImplicitCast, it gets even
harder to tell which it's doing.

Of course, I'm *dying* to get my hands on opImplicitCast, so I'll just
be quiet now... :3

	-- Daniel



More information about the Digitalmars-d mailing list