2d array

chopchop fakeaddress.chop at gmail.com
Sat Jan 1 00:19:56 UTC 2022

I have worked on a little FOSS project (I will ask later for code 
review), I have noticed some limitation on 2d arrays. I haven't 
found the answers on the forum

1) I can not initialize a 2d array in the body of the class,
class A
   Stuff[][] array2d = Stuff.ONE;
One must do that in the ctor

2) The following code yields
Error: cannot implicitly convert expression `3` of type `int` to 
import std;
void main()
     writeln("Hello D");
     int[20][20] array2d;
     array2d = 3;
What I would expect, of course, is to automatically iterate 
through the entire 2d array and set each (i,j) pair to "3".

3) Similarly, it would be nice to have a foreach as follow:
foreach ( cell; array2d)// where i = 0 for all j then i = 1 for 
all j, etc

I guess I can build smthg with opApply but...
Could even be something like
foreach (i, j, cell; array2)

THose are just some remarks. Nice to have stuffs, if someone is 
looking that way. Thanks

More information about the Digitalmars-d mailing list