www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - correct way to set a dynamic 2d array?

reply clayasaurus <clayasaurus gmail.com> writes:
is this the correct way to set a dynamic 2D array?

int[][] dynamic;

dynamic.length = width;

for (int i = 0; i < dynamic.length; i++)
    dynamic[i].length = height;

Just seems a bit weird.
May 30 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:

 is this the correct way to set a dynamic 2D array?
 
 int[][] dynamic;
 
 dynamic.length = width;
 
 for (int i = 0; i < dynamic.length; i++)
     dynamic[i].length = height;
 
 Just seems a bit weird.

Currently, yes. Though it could also be written as ... int[][] dynamic; dynamic.length = width; foreach (inout int[] x; dynamic) x.length = height; -- Derek Melbourne, Australia 31/05/2005 2:33:02 PM
May 30 2005
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Derek Parnell wrote:
 On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:
 
 
is this the correct way to set a dynamic 2D array?

int[][] dynamic;

dynamic.length = width;

for (int i = 0; i < dynamic.length; i++)
    dynamic[i].length = height;

Just seems a bit weird.

Currently, yes. Though it could also be written as ... int[][] dynamic; dynamic.length = width; foreach (inout int[] x; dynamic) x.length = height;

can't you just say this? dynamic[].length = height;
May 30 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 31 May 2005 00:31:47 -0600, Hasan Aljudy wrote:

 Derek Parnell wrote:
 On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:
 
is this the correct way to set a dynamic 2D array?

int[][] dynamic;

dynamic.length = width;

for (int i = 0; i < dynamic.length; i++)
    dynamic[i].length = height;

Just seems a bit weird.

Currently, yes. Though it could also be written as ... int[][] dynamic; dynamic.length = width; foreach (inout int[] x; dynamic) x.length = height;

can't you just say this? dynamic[].length = height;

No. You get this message ... slice expression dynamic[] is not a modifiable lvalue -- Derek Melbourne, Australia 31/05/2005 4:46:02 PM
May 30 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message 
news:k3gx4tkutm62$.wl0ydvkulqru.dlg 40tude.net...
 can't you just say this?
 dynamic[].length = height;

No. You get this message ... slice expression dynamic[] is not a modifiable lvalue

Isn't this something that would be possible with array vectorization? I'd really love this syntax..
May 31 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Jarrett Billingsley wrote:
 "Derek Parnell" <derek psych.ward> wrote in message 
 news:k3gx4tkutm62$.wl0ydvkulqru.dlg 40tude.net...
 
can't you just say this?
dynamic[].length = height;



 I'd really love this syntax.. 

But it would create confusion.. digitalmars.D.bugs/1942 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 02 2005