The following declaration:
const(string[char]) AA1 = [
'a' : "fkclopel",
'b' : "poehfftw"
];
void main(string args[]){}
gives me:
C:...\temp_0186F968.d(1,27): Error: non-constant expression ['a':"fkclopel", 'b':"poehfftw"]
while it would work with other type kinds.
You can initialize associative array constants inside a module constructor:
const /+ or immutable +/ (string [char]) AA1;
static this () {
AA1 = [
'a' : "fkclopel",
'b' : "poehfftw"
];
}
import std.stdio;
void main () {writeln (AA1);}
The manual section on associative array literals explicitly states that "An AssocArrayLiteral cannot be used to statically initialize anything.", though it does not give clues as to why it is so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With