Multiple template alias parameters

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 8 15:51:21 PDT 2015


On Friday, 8 May 2015 at 22:29:28 UTC, Biotronic wrote:
> Sadly, the ... syntax precludes the use of __LINE__ and 
> __FILE__. :(

You can put them in the runtime parameters:

----
void traceVars(alias T, U...)(size_t line = __LINE__, string file 
= __FILE__) {
     import std.stdio : writeln;
     writeln(file, "(", line, ") ", T.stringof, ": ", T);
     static if (U.length > 0) {
         traceVars!(U)(line, file);
     }
}
----

Or you can nest two templates:

----
template traceVars(alias T, U...) {
     void traceVars(size_t line = __LINE__, string file = 
__FILE__)() {
         import std.stdio : writeln;
         writeln(file, "(", line, ") ", T.stringof, ": ", T);
         static if (U.length > 0) {
             alias t = .traceVars!U;
             t!(line, file);
         }
     }
}
----


More information about the Digitalmars-d-learn mailing list