On 8/28/11 10:17 PM, Walter Bright wrote:
On 8/28/2011 12:44 PM, David Nadlinger wrote:
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!

To cast away const, use:

cast()expr

i.e. there is a special syntax for it.

I know about the »it's not a bug, it's a feature« cast() syntax officially added some three (?) months ago, but it should be noted that it also removes shared from the type (incidentally, const_cast removes volatile as well).

Personally, I think that being explicit about the type of operation one intends to perform is a good thing, especially if you are about to subvert the type system. Still, I feel using my own custom set of casting templates would be too confusing for other people reading my code – would anybody else be interested in adding »restricted« casting templates to Phobos?

David

Reply via email to