How can I get the variable name passed as parameter from within a function?

Adam D. Ruppe destructionator at gmail.com
Fri Feb 26 19:37:34 UTC 2021


On Friday, 26 February 2021 at 19:32:52 UTC, Jack wrote:
> I managed to do this with alias parameter in a template:

this is the only way, it needs to be an alias template

> Also, can I short this template function somehow to syntax 
> f!(a) omitting the g?

rename g to f. If the function inside the template's name matches 
the template's own name, the compiler combines them.

of course at that point you can also just write it

void f(alias var)() {
     // do your magic
}


More information about the Digitalmars-d-learn mailing list