Can't use variadic arguments to functions that use templates
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Mon Jul 22 09:48:55 PDT 2013
On Sunday, 21 July 2013 at 07:22:08 UTC, JS wrote:
> void foo(T...)(T t)
> {
> pragma(msg, B(t));
> }
>
> void main() {
> foo("x", "a", "b");
> din.getc();
> }
>
>
> does work. I need to have B generate compile time code so it is
> efficient. Your method calls an actual function at runtime so
> it is nearly as fast as it can be.
My method doesn't make any calls, your foo is a called at
runtime. There is no way to observe a function at compile time;
ctfeWriteln does not exist.
Also don't stringof variable v (I assume you want the value and
not the symbol concatenated.
template B(T...) {
string B(T b) {
string s;
foreach(Type; T) pragma(msg, Type.stringof);
foreach(v; b) s ~= v;
return s;
}
}
string foo(T...)(T t)
{
return B(t);
}
void main() {
enum forced = foo("x", "a", "b");
pragma(msg, forced);
din.getc();
}
More information about the Digitalmars-d-learn
mailing list