Obtaining argument names in (variadic) functions
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 16 13:35:23 PDT 2016
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(){
> myfun(a = 2, b = "two", c = 2.0);
> }
This isn't valid code. The name of the parameters is x[0], x[1], and x[2].
You could do something like:
myfun("a", 2, "b", "two", "c", 2.0);
and process it properly.
-Steve
More information about the Digitalmars-d-learn
mailing list