Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:34:39 UTC, berni wrote: On Friday, 10 February 2017 at 09:25:04 UTC, Daniel Kozak wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:25:04 UTC, Daniel Kozak wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help me? Because it does not see VALUE, you need to use delegate

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread Mike Parker via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:03:16 UTC, berni wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help me? each is a template. As per the template documentation [1],

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread Daniel Kozak via Digitalmars-d-learn
Dne 10.2.2017 v 10:03 berni via Digitalmars-d-learn napsal(a): On Tuesday, 7 February 2017 at 19:06:22 UTC, berni wrote: auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The othe

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Tuesday, 7 February 2017 at 19:06:22 UTC, berni wrote: auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The other two suggestions are beyond my scope yet, but I'll come back, w

Re: Initialization of dynamic multidimensional array

2017-02-07 Thread berni via Digitalmars-d-learn
auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The other two suggestions are beyond my scope yet, but I'll come back, when I improved on my D skills. Thanks for your replies.

Re: Initialization of dynamic multidimensional array

2017-02-07 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 5 February 2017 at 20:33:06 UTC, berni wrote: With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time a

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2017 12:33 PM, berni wrote: With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time and doesn't feel D-ish

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread Daniel Kozak via Digitalmars-d-learn
One another way is use something like this: import std.array, std.algorithm, std.stdio; auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; writeln(arr); Dne 6. 2. 2017 8:21 PM napsal uživatel "berni via Digitalmars-d-learn" < digitalmars-d-learn@puremagic.com>: > On Sunday, 5

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread berni via Digitalmars-d-learn
On Sunday, 5 February 2017 at 21:14:33 UTC, Daniel Kozak wrote: http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a): With X not known at compile

Re: Initialization of dynamic multidimensional array

2017-02-05 Thread Daniel Kozak via Digitalmars-d-learn
http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a): With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i Is there an

Initialization of dynamic multidimensional array

2017-02-05 Thread berni via Digitalmars-d-learn
With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time and doesn't feel D-ish to me.