Top level associative arrays

ANtlord via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 2 02:50:50 PDT 2017


On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote:
>
> Making enum means that value should be available at compile 
> time and AA's are fully dynamic. But if my memory serves me 
> well, you can declare empty AA and delay initialization. So the 
> closest solution is to move initialization of AA to shared 
> module ctor(note that there is difference between shared and 
> non-shared, refer to documentation) such as in this example:
> --------------------------------
>
> static shared this() // <-- module ctors run before main()
> {
>  dict = [
>    "s": "q",
>    "ss": "qq"
>  ];
> }
>
> string[string] dict;
>
> void main()
> { ... dict is already initialized ... }

I know about D's enums and I know about module ctors but my 
question is about difference between array and associative array 
in case of definition in top level of module. Why DMD allows to 
define array and doesn't allow to define associative array.


More information about the Digitalmars-d-learn mailing list