Using "in" with associative arrays and then indexing them (efficiency)

Jonathan M Davis jmdavisProg at
Tue Jan 3 03:34:23 PST 2012

On Tuesday, January 03, 2012 12:27:08 Timon Gehr wrote:
> No, I love declaring variables in if statements and would like it to be
> extended to while statements as well. What I meant is the fact that
> something called 'in' returns a pointer. And the two code snippets I was
> referring to were the two in Matej's post.

Those two code snippets can't possibly result in the same code without the 
compiler assuming that it can safely optimize the first one into the second. 
Certainly, with a user-defined type, that would be impossible. With the AA, 
since it's essentially built-in, it may decide that it can make that 
assumption, but it could definitely result in different behavior if you were 
dealing with shared or the like, and there's nothing requiring the compiler to 
make such an optimization.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list