On 09/11/2011 01:23 AM, 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
It is possible to determine the number of dimensions automatically
during compile time, eg like this:
template NumDim(T){enum NumDim=0;}
template NumDim(T:T[]){enum NumDim=NumDim!T+1;}
unittest{
static assert(NumDim!int==0);
static assert(NumDim!(int[])==1);
static assert(NumDim!(int[][])==2);
static assert(NumDim!(int[][][])==3);
}