Top level associative arrays

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


On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote:
> Hello! Is it possible to define associative array on top level 
> of module?
> I try to compile this code and I get message `Error: 
> non-constant expression ["s":"q", "ss":"qq"]`
>
> import std.stdio;
>
> auto dict = [
> 	"s": "q",
> 	"ss": "qq"
> ];
> void main()
> {
> 	writeln(val);
> }
>
> I solved it by replacement of word `auto` by `enum`. It is 
> acceptable for me. But I notice some inconsistency of logic. 
> When I define simple array I don't get same compile error and 
> it doesn't lead to define this array using enum. What is key 
> difference between them in this case?
>
> Thanks. Sorry if my English is not clear.

Sorry. There is should be `writeln(dict["s"]);` instead 
`writeln(val);`




More information about the Digitalmars-d-learn mailing list