associative arrays

Jonathan M Davis jmdavisProg at
Sun Jan 8 03:18:03 PST 2012

On Sunday, January 08, 2012 11:33:51 simendsjo wrote:
> I was thinking it could be a shorthand for the following:
> auto item = key in aa;
> if (item) key.remove(key);

I take it that you then intend to use item after that? I'm not sure that item 
is actually valid at that point. It points to memory which _was_ inside of aa 
but may or may not be now, depending on the AA implementation, and it may or 
may not be reused by aa. Because it's on the GC heap, the memory itself won't 
be invalid, but the memory could be reused by the AA for another element, 
depending on its implementation. If you're lucky, it's memory that's just 
sitting on the GC heap and now unrelated to the AA, but I wouldn't bet on it.

I would _not_ consider that to be good code. It's just asking for trouble.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list