multi-dimensional dynamic arrays

Jay Norwood via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 06:34:23 PST 2016


On Friday, 19 February 2016 at 14:26:25 UTC, Steven Schveighoffer 
wrote:
>
> Try ub[0].length = 3. You are trying to change the length on 
> one of the static arrays.

yes, right these compile.  I was surpised it wouldn't accept the 
append with just an int.

	int[1][][1] ubb;
	ubb[0].length = 3;
	ubb[0] ~= [5];
>
> If you had more than 1 as a static dimension, then you would 
> have to change the length of *each* of the elements.
>
> Arrays in D, are actually quite simple. Any time you see:
>
> T[]
>
> It's a dynamic array of T. Any time you see:
>
> T[N]
>
> Where N is a compile-time integer, it's a static array of T.
>
> So dissecting your type:
>
> int[1][][1]
>
> So the outer-most T is int[1][]. You have a single instance of 
> this, in a static array.
>
> At the next level, T is int[1], where you have a dynamic array 
> of these.
>
> Finally, at the 3rd level, T is int, you have a single element 
> in a static array of int.
>
> -Steve




More information about the Digitalmars-d-learn mailing list