Templated Interfaces?

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Aug 27 22:21:54 PDT 2008


"Ary Borenszweig" <ary at esperanto.org.ar> wrote in message 
news:g92a1n$a9p$1 at digitalmars.com...
> Jarrett Billingsley a écrit :
>> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
>> news:g911lg$ja5$1 at digitalmars.com...
>>> "Ary Borenszweig" <ary at esperanto.org.ar> wrote in message 
>>> news:g8vp2l$11nf$1 at digitalmars.com...
>>>> Ouch. I first wrote
>>>>
>>>> I!(char)[3] array = new I!(char)[3];
>>>>
>>>> which compiles, and makes array a static array (you can't append to 
>>>> it). Then, for simplicity, I changed the type to auto... it seems new 
>>>> makes a dynamic array, but then it is implicitly converted to a static 
>>>> one, right?
>>> No.  When you write
>>>
>>> auto x = Y;
>>>
>>> it is identical to writing
>>>
>>> typeof(Y) x = Y;
>>>
>>> In this case, typeof(new I!(char)[3]) is I!(char)[].  A dynamic array.
>>>
>>
>> Unless you meant in the non-auto case?  In which case I'm kind of 
>> surprised the compiler allows it since it normally does not allow you to 
>> reassign static arrays.
>
> Exactly, I meant in the non-auto case. What's going on there?

OK, I just tried it and stepped through and.. what it seems to do is it 
allocates an int[] of length 3 on the heap, then slice-copies it into the 
stack-allocated static array.  No reference to the array on the heap is 
kept.

Weird. 




More information about the Digitalmars-d-learn mailing list