Immutable static arrays
Daniel Murphy
yebblies at nospamgmail.com
Fri Mar 16 20:59:55 PDT 2012
"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message
news:mailman.803.1331956296.4860.digitalmars-d at puremagic.com...
> Is this a bug?
>
> import std.stdio;
> void main() {
> immutable(int)[4] a;
> immutable(int[4]) b;
> writeln(typeid(a));
> writeln(typeid(b));
> }
>
> Output:
>
> immutable(int[4])
> immutable(int[4])
>
> 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???).
>
>
> T
>
> --
> It is widely believed that reinventing the wheel is a waste of time; but
> I disagree: without wheel reinventers, we would be still be stuck with
> wooden horse-cart wheels.
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.
More information about the Digitalmars-d
mailing list