Can't use variadic arguments to functions that use templates

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Jul 20 11:57:16 PDT 2013


On Saturday, 20 July 2013 at 18:27:23 UTC, JS wrote:
> is there any way to pass t directly to A?
>
> template A(T...) doesn't seem work nor does using an alias. (or 
> at least, when I try to foreach over it, it doesn't work).

template A(size_t L) {
     enum A = L;
}

template B(T...) {
void B(T b) {
     import std.stdio;
     foreach(Type; T) {
         pragma(msg, Type.stringof);
     }
     foreach(v; b) {
         writeln(v);
     }
}}

void foo(T...)(string s, T t) {
     auto n = A!(t.length);
     B(t);// t is runtime information
          // T is compile time information
}

void main() {
     foo("x", 1, 2);
}


More information about the Digitalmars-d-learn mailing list