Thread overview |
---|
January 14, 2020 Filling an associated array of associated arrays | ||||
---|---|---|---|---|
| ||||
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. |
January 14, 2020 Re: Filling an associated array of associated arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jamie | 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. |
January 15, 2020 Re: Filling an associated array of associated arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to mipri | 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
|
Copyright © 1999-2021 by the D Language Foundation