Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 04, 2011 Implicit .dup inserting into AA keyed on char[], or not? | ||||
---|---|---|---|---|
| ||||
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? |
March 04, 2011 Re: Implicit .dup inserting into AA keyed on char[], or not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | But it errors out? Error: associative arrays can only be assigned values with immutable keys, not char[] |
March 04, 2011 Re: Implicit .dup inserting into AA keyed on char[], or not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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
|
March 04, 2011 Re: Implicit .dup inserting into AA keyed on char[], or not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.2156.1299206161.4748.digitalmars-d-learn@puremagic.com... > 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. > Ahh, I'm still on 2.050 so that's probably why it worked for me. (There's no particular reason I haven't updated to 2.051 or 2.052, I just got busy with non-D stuff for awhile and haven't gotten around to it.) |
Copyright © 1999-2021 by the D Language Foundation