Initialization of dynamic multidimensional array

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 10 01:25:04 PST 2017


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 other two suggestions are beyond my scope 
>> yet, but I'll come back, when I improved on my D skills. Thanks for 
>> your replies.
>
> 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 insted of string 
something like this:

arr.each!(a=>a[]=VALUE);




More information about the Digitalmars-d-learn mailing list