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);`


Reply via email to