Re: Obtaining argument names in (variadic) functions

2016-03-20 Thread JR via Digitalmars-d-learn
On Thursday, 17 March 2016 at 14:12:38 UTC, Edwin van Leeuwen wrote: On Thursday, 17 March 2016 at 13:53:00 UTC, JR wrote: Interesting, any idea if it is possible to do assignment within template.. Either: printVars!(int abc=5,string def="58")(); or something like

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 21:05:43 UTC, JR wrote: On Wednesday, 16 March 2016 at 20:43:09 UTC, jkpl wrote: I try to anticipate the reason why you want this. [...] I use something *kinda* sort of similar in my toy project to print all fields of a struct, for debugging purposes when stuff

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
On Thursday, 17 March 2016 at 11:52:13 UTC, Edwin van Leeuwen wrote: 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,

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 4:24 PM, 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(){

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
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, " : ",

Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
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

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread Edwin van Leeuwen via Digitalmars-d-learn
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;

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread jkpl via Digitalmars-d-learn
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, " : ",

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote: 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

Re: Obtaining argument names in (variadic) functions

2016-03-18 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Thursday, 17 March 2016 at 13:53:00 UTC, JR wrote: 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"); What would the use-cases for those be? I don't think the

Re: Obtaining argument names in (variadic) functions

2016-03-18 Thread JR via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:43:09 UTC, jkpl wrote: I try to anticipate the reason why you want this. [...] I use something *kinda* sort of similar in my toy project to print all fields of a struct, for debugging purposes when stuff goes wrong. Getting the names of the member variables