Obtaining argument names in (variadic) functions

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 17 04:52:13 PDT 2016


On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote:
>
>
> void printVars(Args...)()
> if (Args.length > 0)
> {
>     import std.stdio : writefln;
>
>     foreach (i, arg; Args) {
>         writefln("%s\t%s:\t%s", typeof(Args[i]).stringof, 
> Args[i].stringof, arg);
>     }
> }
>
> void main() {
>     int abc = 3;
>     string def = "58";
>     float ghi = 3.14f;
>     double jkl = 3.14;
>
>     printVars!(abc,def,ghi,jkl)();
> }

Interesting, any idea if it is possible to do assignment within 
template.. Either:

printVars!(int abc=5,string def="58")();
or something like
printVars!("abc","def",ghi)(5,"58");



More information about the Digitalmars-d-learn mailing list