Possible D2 solution to the upcasting array problem, and a related problem with const and nested arrays
Stewart Gordon
smjg_1998 at yahoo.com
Tue Jan 6 17:06:58 PST 2009
Denis Koroskin wrote:
<snip>
> Nice, but I don't like the proposed syntax much, especially these:
>
> cast(!const BaseClass[])
> cast(!const const(int)[][])
>
> I believe it would be better to split them into two separate casts as
> follows:
>
> BaseClass[] base = cast(BaseClass[])cast(!const)derived;
Won't work. DerivedClass[] still needs to convert to
const(BaseClass)[], not to BaseClass[]. Would have to be the more
long-winded
BaseClass[] base = cast(!const) cast(const(BaseClass)[]) derived;
and moreover, there'd be no way to do the casts to const(int)[][].
Unless you want cast(!const) to cast to a purely internal intermediate
type that suppresses const-checking altogether.
Stewart.
More information about the Digitalmars-d
mailing list