Variadic template problems..?

simendsjo simen.endsjo at pandavre.com
Sat Jun 25 09:08:37 PDT 2011


I'm trying to create an array of arrays in a templated struct, but I'm 
having some problems.
Given the struct below, I want to construct an "S.Array[3]" array.
My first template solution, T, also doesn't compile.. Why?

struct S(int C, int R, E) {
     alias E[R][C] Array;
}

/+
// This gives me an syntax error, but I have no idea why
// "no identifier for declarator A[0]"
template T(A...) {
     alias A[0].Array[A.length] T;
}
+/

// This works though..
template U(T, A...) {
     alias T.Array[A.length+1 /+include+/] U;
}

unittest {
     alias S!(1,1,float) S1;
     alias U!(S1, S1) Arr; // I want float[1][1][2]

     static assert(Arr.length == 2); // ok
     writeln(typeid(Arr[0])); // float[1][1][2][0] ... shouldn't this be 
float[1][1][2]?
     writeln(typeid(typeof(Arr[0]))); // float[1][1] ... What happens here?
     writeln(typeid(S1.Array)); // float[1][1]
}


More information about the Digitalmars-d-learn mailing list