"The total size of a static array cannot exceed 16Mb."
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Oct 2 11:23:06 PDT 2007
"Janice Caron" <caron800 at googlemail.com> wrote in message
news:mailman.353.1191333299.16939.digitalmars-d at puremagic.com...
> On 10/2/07, Vladimir Panteleev <thecybershadow at gmail.com> wrote:
>> P.S. I believe your function can be reduced to this without any
>> significant changes in behavior:
>>
>> T[][] ret = new T[][x];
>> foreach(ref row;ret)
>> row.length = y;
>>
>> return ret;
>
> For that matter, I think you could also do:
>
> template MultiDimArray(T,int N)
> {
> static if (N == 1)
> typedef T[] MultiDimArray;
> else
> typedef MultiDimArray!(T,N-1)[] MultiDimArray;
> }
>
> MultiDimArray!(T,N) MakeMultiDimArray(T,int N)(int dim, int[]
> others...)
> {
> static if (N == 1)
> return new T[dim];
> else
> {
> MultiDimArray!(T,N) t;
> t.length = dim;
> foreach(ref a;t) a =
> MakeMultiDimArray!(T,N-1)(others[0],others[1..$]);
> return t;
> }
> }
You've basically implemented, in templates, what you can already do with the
language syntax. MultiDimArray!(int, 3) will turn into int[][][], and the
functionality of MakeMultiDimArray is already covered by array new-ing, i.e.
new int[][][](10, 20, 30).
And it's still an array-of-arrays.
More information about the Digitalmars-d
mailing list