Wrong lowering for a[b][c]++

Alvaro alvaroDotSegura at gmail.com
Wed Mar 21 13:36:47 PDT 2012


El 21/03/2012 19:29, H. S. Teoh escribió:
> A question was asked on the d-learn forum about why this throws a
> RangeError:
>
> 	int[string][int] map;
> 	map["abc"][20]++;
>

IIRC, that worked fine for me a few weeks ago. And I found it to be just 
great that it did. I'll have to re-check but I remember it like this.

I had to produce a new tabular dataset from an original by accumulating 
elements (rows) sharing some attribute values.

The idea was to read that line by line, split into attributes and do:

  // this will hold the counts:

  int[int][int][int][string] count;

  // for each row, split field1 .. field5 (field4 is a string)

  count[field1][field2][field3][field4] += field5;


And that just worked IIRC, without initializing anything!

At the end, to iterate all the hyper map and write it out, we used 
nested foreachs, something like:

foreach(field1, item1; count)
     foreach(field2, item2; item1)
         foreach(field3, item3; item2)
             foreach(field4, field5; item3)
                 writeln(field1, field2, field3, field4, field5);

I'm trying to remember if we had to do something special to make it work...



More information about the Digitalmars-d mailing list