On 2017-05-02 09:48, 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.

Note that when declared as "enum", all places it's referenced, a new associative array will be allocated.

--
/Jacob Carlborg

Reply via email to