pass variable names

Daniel Keep daniel.keep.lists at gmail.com
Thu Jul 9 21:24:56 PDT 2009



Saaa wrote:
> Is it possible to get the passed variable name � la:
> --
> void functio(A...)(ref A a)
> {
>     writefln(typeof(a[0]));
> }
> int i;
> functio(i); // prints "i"

No.

You should be able to get the name using an alias:

void func(alias var)()
{
    writefln(var.stringof);
}

But you can't do it at runtime.

> Also how do I fix this:
> --
> functio(`i`); // Error: "i" is not an lvalue

You have to store the literal in a variable.


More information about the Digitalmars-d-learn mailing list