On Wednesday, 16 March 2016 at 20:24:38 UTC, data pulverizer
wrote:
Hi D gurus,
is there a way to obtain parameter names within the function
body? I am particularly interested in variadic functions.
Something like:
void myfun(T...)(T x){
foreach(i, arg; x)
writeln(i, " : ", arg);
}
void main(){
myfun(a = 2, b = "two", c = 2.0);
}
// should print
a : 2
b : two
c : 2.0
Thanks in advance
Loving the mixins and tuples
You can do it precisely like that if the variables/symbols you
pass as (template) arguments are properly declared first.
http://dpaste.dzfl.pl/0b452efeaaab
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)();
}