'auto' with AA

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 28 10:18:15 PDT 2014


On 04/28/2014 12:12 AM, David Held wrote:

 >  Here is a compilable example which fails:
 >
 > void main()
 > {
 >      double[int][string] nestedAA;
 >      nestedAA["test"] = null;

I think I see what's going on. The line above has almost no effect. For 
example, it does not populate "test" with an empty double[int] AA. I 
think there is conceptually an entry but that entry will be created 
lazily when an element is added to it.

 >      auto innerAA = nestedAA["test"];

That line is not a reference to "test" but another null:

     assert(innerAA is null);

 >      innerAA[42] = 3.14;

That entry populates the local AA. The "test" entry is still null.

 >      assert(42 in nestedAA["test"]);

And that line fails.

Ali



More information about the Digitalmars-d-learn mailing list