www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Filling an associated array of associated arrays

reply Jamie <notme gmail.com> writes:
I'm trying to initialise an associated array of associated arrays 
with values, taking the same approach I would for an associated 
array:

string[string][string] table = [
     "info" : [
         "equation" : "H2 + I2 <=> 2HI",
         "type" : "elementary",
         ],
     "frc" : [
         "A" : "1.2e9",
         "n" : "1.2e9",
         "C" : "1.2e9",
         ],
     ];

But I'm getting the error `Not an associative array initializer'.
Is there a way to do this in the fashion that I'm trying?

I can declare it like

string[string][string] table;
table["info"]["equation"] = "H2 + I2 <=> 2HI";
table["info"]["type"] = "elementary";

But don't see why the first way wouldn't work.
Jan 14 2020
parent reply mipri <mipri minimaltype.com> writes:
On Tuesday, 14 January 2020 at 23:23:51 UTC, Jamie wrote:
 I'm trying to initialise an associated array of associated 
 arrays with values, taking the same approach I would for an 
 associated array:
This works: import std.stdio; void main() { string[string][string] table = ([ "info" : [ "equation" : "H2 + I2 <=> 2HI", "type" : "elementary", ], "frc" : [ "A" : "1.2e9", "n" : "1.2e9", "C" : "1.2e9", ], ]); writeln(table); } c.f. https://issues.dlang.org/show_bug.cgi?id=17607 I found that by searching the forums for your error.
Jan 14 2020
parent Jamie <notme gmail.com> writes:
On Tuesday, 14 January 2020 at 23:59:59 UTC, mipri wrote:
 On Tuesday, 14 January 2020 at 23:23:51 UTC, Jamie wrote:

 c.f. https://issues.dlang.org/show_bug.cgi?id=17607

 I found that by searching the forums for your error.
That has fixed my issue. I had searched the forums for relevant topics, but not the error itself. A lesson for me. Cheers
Jan 14 2020