Immutable static arrays
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 16 20:59:19 PDT 2012
On Fri, Mar 16, 2012 at 08:53:06PM -0700, H. S. Teoh wrote:
[...]
> 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???).
P.S. The error message is:
newAA.d(58): Error: slice this.key[] is not mutable
which is odd, because the code reads:
struct Slot
{
Slot *next;
hash_t hash;
Key key;
Value value;
this(K)(hash_t h, K k, Value v, Slot *_next=null) if (keyCompat!K)
{
static if (is(K : Key))
key = k; // line 58
else ...
}
...
}
(This is being instantiated with Key == immutable char[4]).
Why is the assignment being translated into a slice for the assignment?
T
--
Nobody is perfect. I am Nobody. -- pepoluan, GKC forum
More information about the Digitalmars-d
mailing list