www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - another reason to have AAs not insert on lookup

Over on the D.learn group someone had a property foo() that returned an AA 
and then wanted to say foo["hello"] to lookup an element. But since lookup 
can insert and inserting can change the size and ptr of an AA the compiler 
needs the result of foo() to be an lvalue, which it isn't. I recommended 
that they store the result of foo() in a temporary bar and write 
bar["hello"] since in their situation they know "hello" is in the AA so it 
will never actually insert. If indexing into an AA didn't require an lvalue 
then they wouldn't have had the problem, so I figure I'd post that comment 
here as more info for the discussion in AA lookup behavior.

It would still be true that foo["hello"] = "world" would need an lvalue so 
that would error.

Mar 31 2005