TIL: statically initializing an Associative Array
Andy Valencia
dont at spam.me
Tue May 7 00:10:27 UTC 2024
I had a set of default error messages to go with error code
numbers, and did something along the lines of:
string[uint] error_text = [
400: "A message",
401: "A different message"
];
and got "expression .... is not a constant"
I eventually found this discussion:
https://issues.dlang.org/show_bug.cgi?id=6238
I understand that it's problematic, but a message which makes it
clearer that compile-time initialization of global AA's are not
supported? Because it cost me about a half hour trying to figure
out what I was doing wrong.
(My workaround was to initialize the data structure once during
app startup.)
More information about the Digitalmars-d-learn
mailing list