On 09/11/2011 02:09 AM, Timon Gehr wrote:
On 09/11/2011 02:03 AM, Andrei Alexandrescu wrote:
On 9/10/11 6:23 PM, dsimcha wrote:
On 9/10/2011 5:37 PM, dsimcha wrote:
* newArray could only take the element type as a template parameter;
the
number of dimensions in unequivocally determined from the number of
arguments.
Good point. Actually, this can probably be changed in
std.array.uninitializedArray, too. There was some reason why I did it
the way I did, but I don't remember why. I'll look into it.
Ok, now I remember. It was so that if you give too many dimensions, it's
a compile time error, not a runtime error. For example:
auto foo = alloc.newArray!(int[][])(8, 6, 7, 5, 3, 0, 9); // Error
If you just require
auto foo = alloc.newArray!int(8, 6, 7, 5, 3, 0, 9);
there's never an error, the array is created with as many dimensions as
numbers. A mistake in choosing that number will never get unnoticed
because the array type will be screwed up.
Andrei
The current interface allows to only initialize the first 1 to
nDimensions!T dimensions:
auto foo = alloc.newArray!(int[][])(2); // OK
assert(foo.length==2);
assert(foo[0] is null);
Well, your proposal does too:
auto foo = alloc.newArray!(int[])(2);
But I think that really looks like the creation of a one-dimensional array.