arrays in DMD V2

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 19 09:56:43 PDT 2014


On 04/19/2014 09:14 AM, steven kladitis wrote:

 > // does not work

I think you are thinking in terms of C's syntax. Unlike C, array 
definition syntax is consistent in D.

I inserted spaces below to make it stand out:

     int[]  [string] arr;

The definition above is in the following form:

     ValueType[KeyType] arr;

So, it is an associative array of string keys and int[] values. If you 
think that way, the following program makes sense:

void main()
{
     int[][string][string][string] a5;
     int[string][int][string][float] a6;
     int[int][int][string] a7;

     a5 = [ "a" : [ "b" : [ "c" : [ 1 ] ] ] ];
     a6 = [ 1.0f : [ "a" : [ 1 : [ "b": 5 ] ] ] ];
     a7 = [ "a" : [ 1 : [ 2 : 3 ]]];
}

Ali



More information about the Digitalmars-d-learn mailing list