Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 10, 2009 pass variable names | ||||
---|---|---|---|---|
| ||||
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"
--
Also how do I fix this:
--
functio(`i`); // Error: "i" is not an lvalue
--
|
July 10, 2009 Re: pass variable names | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | 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. |
July 10, 2009 Re: pass variable names | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Keep | > No. > > You should be able to get the name using an alias: > > void func(alias var)() > { > writefln(var.stringof); > } Can this be combined with the tuple parameter? > > 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. I needed it to get my function to accept func( `name_i`, i, `name_ar`, ar, `name_b`, b ..etc..) only the variables need to be ref. |
July 10, 2009 Re: pass variable names | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | Hello Saaa,
>> No.
>>
>> You should be able to get the name using an alias:
>>
>> void func(alias var)()
>> {
>> writefln(var.stringof);
>> }
> Can this be combined with the tuple parameter?
>
I'll seconds this, there doesn't seem to be any way to generate tuples of aliases and this is another cases where it would be handy.
|
Copyright © 1999-2021 by the D Language Foundation