Googling is so good for necro thread resurrection.

What is idiomatic way in D to initialize static immutable AA to be accessible in CTFE at the same? static this() won't help here, unfortunately.

On Wednesday, 9 November 2011 at 10:44:08 UTC, Gor Gyolchanyan wrote:
I think this is a bug and i even recall seeing it in bugzilla, but i
don't have a link to it.

On Wed, Nov 9, 2011 at 10:43 AM, bearophile <bearophileh...@lycos.com> wrote:
Is it possible to modify DMD to allow a program like:


immutable int[int] aa = [1:15, 2: 7];
void main() {}


With the latest DMD it gives:
test.d(1): Error: non-constant expression [1:15,2:7]

Global immutable associative arrays are handy in script-like programs, I use them now and then in Python (despite they are not immutable). This is a workaround for script-like programs, that I sometimes use:


immutable int[int] aa;
static this() {
   aa = [1:15, 2: 7];
}
void main() {}


But when possible I try to avoid using static this.

Bye,
bearophile

Reply via email to