how to initialize immutable 2 dim array

2010-10-31 Thread Michal Minich
I have global static array and I want it to initialize in module constructor, but I get error. I there way to do it without using enum. immutable int[5][5] arr; static this () { arr = new int[5][5]; // Error: slice arr[] is not mutable }

Re: how to initialize immutable 2 dim array

2010-10-31 Thread Stewart Gordon
On 31/10/2010 17:10, Michal Minich wrote: I have global static array and I want it to initialize in module constructor, but I get error. I there way to do it without using enum. So you want to initialise it with data acquired at runtime, but make it immutable once initialised? immutable

Re: how to initialize immutable 2 dim array

2010-10-31 Thread bearophile
Michal Minich: I like the simple workaround with using mutable pointer, but I'm getting access violation error even when arr is mutable ... and really don't understand why... :( int[256][256] arr; static this () { int[256][256]* pArr = arr; for (int y = 0; y =

Re: how to initialize immutable 2 dim array

2010-10-31 Thread Michal Minich
On Sun, 31 Oct 2010 14:53:42 -0400, bearophile wrote: import std.stdio: writeln; int[256][256] arr; static this () { auto pArr = arr; foreach (y; 0 .. (*pArr)[0].length) foreach (x; 0 .. (*pArr).length) (*pArr)[x][y] = x * y; } void main() {

Re: how to initialize immutable 2 dim array

2010-10-31 Thread bearophile
Michal Minich: I need to use this workaround because global array I want to initialize in module constructor is immutable. A pointer to a immutable array is immutable. So you aren't improving the code, just making it more obfuscated. So there is zero need to use a pointer. Immutable data is

Re: how to initialize immutable 2 dim array

2010-10-31 Thread bearophile
Some people have recently discussed about this problem and a bug report was proposed. Until some language-supported solution is found, the simpler solution for this problem may be to use a static mutable array... http://d.puremagic.com/issues/show_bug.cgi?id=5147

Re: how to initialize immutable 2 dim array

2010-10-31 Thread Michal Minich
On Sun, 31 Oct 2010 17:21:50 -0400, bearophile wrote: Some people have recently discussed about this problem and a bug report was proposed. Until some language-supported solution is found, the simpler solution for this problem may be to use a static mutable array...