Article about problems & suggestions for D 2.0

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Aug 28 13:52:07 PDT 2011


On 08/28/2011 02:44 PM, David Nadlinger wrote:
> On 8/28/11 8:54 PM, Alex Rønne Petersen wrote:
>> const_cast is the root of all evil. I really don't want to see it in D.
>>
>> - Alex
>
> It is already in D, and in an, in my personal opinion, much worse way:
> You can just cast away const/immutable with cast().
>
> What do you propose for the situations where you need to cast away
> const? (Yes you'll find yourself in one of them from time to time in the
> real world, e.g. when dealing with legacy/C code…)
>
> I know that this is not the general consensus, but I very much like the
> C++ casting operators, because you can quickly get a rough idea what is
> going on when you see a cast in the code, whereas for D, cast() be
> anything between a perfectly harmless downcast (if checking for null,
> obviously), changing the storage class (const/immutable/shared), or
> causing the bytes stored to be interpreted in a completely different way!
>
> David

It is quite easy to define C++-like cast operators as D functions. If 
there's enough demand for that, we may include such in the standard library.

Andrei


More information about the Digitalmars-d mailing list