Casting away const and invariant
Janice Caron
caron800 at googlemail.com
Sun Sep 9 05:26:06 PDT 2007
I've noticed that you can do this in D2.0, without knowing the type of p.
auto q = cast(const) p;
The type of q is now the type of p, but with added constness. However,
if you want to take the constness away, you must explicitly specify
the full type, as in:
auto r = cast(int *) q;
Seems to me, this is a good place for coding errors to creep in, and
it's the exact reason that const_cast<> was introduced into C++. So,
how about allowing
auto r = cast(!const) q; /* currently will not compile */
which would eliminate that sort of error.
More information about the Digitalmars-d
mailing list