Immutable static arrays

Daniel Murphy yebblies at nospamgmail.com
Fri Mar 16 21:33:36 PDT 2012


"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message 
news:mailman.805.1331958621.4860.digitalmars-d at puremagic.com...
> On Sat, Mar 17, 2012 at 02:59:55PM +1100, Daniel Murphy wrote:
> [...]
>> > So there's no tail-const type for static arrays?
>> >
>> > More to the point, how should AA's with immutable static array keys
>> > be implemented? The current implementation doesn't work at all
>> > because the input static array can't be assigned to the Slot (the
>> > static array field in Slot is completely immutable, even from the
>> > Slot ctor???).
> [...]
>> This is correct.  It's the same as for primitive types.  Because they
>> implicitly convert to immutable, AAs should store a mutable copy.
>> T[N] should be handled almost the same as T.
> [...]
>
> So string[immutable int[4]] should store int[4] as key?
>
> I guess I just found it strange that assigning to a string
> (==immutable(char)[]) field is OK, but assigning to immutable(char[4])
> is not.
>

The difference is dynamic arrays contain an indirection, static arrays 
don't.  Treat them the same as you do primitive types and they should work. 
(apart from compiler bugs) 




More information about the Digitalmars-d mailing list