Implicit .dup inserting into AA keyed on char[], or not?

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 3 18:35:50 PST 2011


On Thursday 03 March 2011 17:54:46 Nick Sabalausky wrote:
> In D2, if you do this:
> 
> void foo(char[] key)
> {
>     bool[char[]] aa;
>     aa[key] = true;
> }
> 
> Does that last line allocate a duplicate of key's data?

More like it's illegal. The key type for associative arrays _must_ be immutable. 
Previously, that wasn't check for by the compiler, which meant that it was 
possible to change the values of keys (not good), which could quickly result in 
an AA in an invalid state. Not too long ago, however, it was fixed so that that's 
not legal.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list