The Status of Const

Mafi mafi at example.org
Tue Aug 17 06:00:15 PDT 2010


Am 17.08.2010 13:48, schrieb Mafi:
> Am 17.08.2010 12:05, schrieb Pelle:
>> On 08/17/2010 01:44 AM, Steven Schveighoffer wrote:
>>> On Mon, 16 Aug 2010 19:06:56 -0400, Simen kjaeraas
>>> <simen.kjaras at gmail.com> wrote:
>>>> Uhm, it works in D:
>>>>
>>>> class C {}
>>>> class D : C {}
>>>>
>>>> void main( ) {
>>>> D[] a;
>>>> C[] b = a;
>>>> }
>>>
>>> Yes, I was about to say that except that is a bug kind of. The type
>>> system should only allow casting D[] to const(C)[].
>>
>> class C { }
>> class D : C { }
>> class E : C { }
>>
>> void append_to(ref const(C)[] cs, const(C) c) { cs ~= c; }
shit, didn't see the ref. Then everything is right.
>>
>> D[] ds;
>> append_to(ds, new E);
>>
>>
>> *ahem*
>> D[] can not be converted to const(C). That it works today is pretty
>> terrible. Rewrite the append_to to work with Objects, and well. :-)
>
>(...)
>
> Mafi



More information about the Digitalmars-d mailing list