How to make a global immutable associative array?

dnspies dspies at ualberta.ca
Tue Mar 18 17:16:29 PDT 2014


I want to create a global immutable associative array and have it 
be accessible from anywhere at compile-time.  How can I do that?

With:
immutable int[int] aa = [1:2,3:4];

I get:
source/thing.d(1): Error: non-constant expression [1:2, 3:4]

And with:
immutable int[int] aa;

static this(){
	aa = [1:2,3:4];
}

int c = aa[3];

I get:
source/thing.d(7): Error: static variable aa cannot be read at 
compile time

Also associative arrays don't seem to have a .idup

Is there any other way to do this?


More information about the Digitalmars-d mailing list