Variadic templates
Daniel Keep
daniel.keep.lists at gmail.com
Tue Nov 7 18:28:53 PST 2006
rm wrote:
>
> should this work:
>
>>>>
> import std.stdio;
>
> template Templ(T, R ...)
> {
> static if (R.length) {
> const char [] s = "yes";
> // writefln(s);
> } else {
> const char [] s = "no";
> // writefln(s);
> }
> }
>
>
> void main()
> {
> mixin Templ!(int,char);
> writefln(s); // can't put this into the template
> }
> <<<
>
>
> It compiles, it runs fine, but I'm not using function templates.
> otoh, try to bring the lines commented out into play, it won't compile
> anymore.
>
> bye,
> roel
That's because you can't have executable statements in a template. I
really wish you could, tho.
If you want to write those out at COMPILE TIME, however, you can change
> writefln(s);
To:
> pragma(msg, s);
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list