www.digitalmars.com         C & C++   DMDScript  

D - Multi-Dimensional array suggestion

reply Mark Arts <Mark_member pathlink.com> writes:
I wanted to make a suggestion about multi dimensional array assignments:

When I define
int[4] array;
I can use
array[] = 5;
which is by definition the same as
for (int i=0; i<4; i++)
array[i] = 5;

But when I define
int[4][5] array2;
I cannot use
array2[][] = 5;
because this is the same as
for (int i=0; i<5; i++)
array2[][i] = 5;
 I get the error "cannot convert int to int[4]".

Wouldn't it be more logical to define array2[][]=5 as
for (int i=0; i<4; i++)
array[i][] = 5;
, which would be the same as
for (int i=0; i<4; i++)
for (int j=0; j<5; j++)
array[i][j] = 5;
? This would make multi-dim array initialising way easier, without having to use
loops when the dimension is higher than 1.
Jan 07 2004
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
That sounds like the right way to do it, but currently none of this stuff is
implemented in DMD.

Sean

"Mark Arts" <Mark_member pathlink.com> wrote in message
news:btgqcf$16hu$1 digitaldaemon.com...
 I wanted to make a suggestion about multi dimensional array assignments:

 When I define
 int[4] array;
 I can use
 array[] = 5;
 which is by definition the same as
 for (int i=0; i<4; i++)
 array[i] = 5;

 But when I define
 int[4][5] array2;
 I cannot use
 array2[][] = 5;
 because this is the same as
 for (int i=0; i<5; i++)
 array2[][i] = 5;
  I get the error "cannot convert int to int[4]".

 Wouldn't it be more logical to define array2[][]=5 as
 for (int i=0; i<4; i++)
 array[i][] = 5;
 , which would be the same as
 for (int i=0; i<4; i++)
 for (int j=0; j<5; j++)
 array[i][j] = 5;
 ? This would make multi-dim array initialising way easier, without having

 loops when the dimension is higher than 1.

Jan 07 2004