Variadic template problems..?
simendsjo
simen.endsjo at pandavre.com
Sat Jun 25 10:48:37 PDT 2011
On 25.06.2011 18:08, simendsjo wrote:
> 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]
> }
I think the error in T might be a bug. The following works:
template T2(A...) {
alias A[0] First;
alias First.Array[A.length] T;
}
writeln(typeid(Arr2.T)); // Now this actually prints float[1][1][2] as I
wanted!
More information about the Digitalmars-d-learn
mailing list