More magical AA semantics

Jonathan M Davis jmdavisProg at gmx.com
Sat Jan 12 17:33:24 PST 2013


On Saturday, January 12, 2013 16:56:13 Andrei Alexandrescu wrote:
> >> As well, what about
> >> //----
> >> immutable(int)[int] aa;
> >> aa[0] = 5;
> >> //----
> >> This should work, right?
> > 
> > That should definitely work. That's how you add elements to AA. My gripe
> > with something like ++a[0] working when there's no a[0] is that you'd be
> > adding to an element that doesn't exist yet.
> 
> Shouldn't work.

Yeah, you're right. I didn't think through that one enough. Why inserting 
immutable elements would work ideally, there's no difference between inserting 
and assigning as far as the operatiors used or functions called go, so we're 
forced to disallow insertion as well as assignment. So, assuming that the 
functions for querying the AA are const, there's not much difference between an 
AA of immutable elements and an immutable AA.

- Jonathan M Davis


More information about the Digitalmars-d mailing list