Top level associative arrays

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


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.


More information about the Digitalmars-d-learn mailing list