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

2021-02-26 Thread Jack via Digitalmars-d-learn
On Friday, 26 February 2021 at 19:37:34 UTC, Adam D. Ruppe wrote: 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

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

2021-02-26 Thread Adam D. Ruppe via Digitalmars-d-learn
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

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

2021-02-26 Thread Jack via Digitalmars-d-learn
int a = 10; f(a); // print "a" int b = 10; f(b); // print "b" I managed to do this with alias parameter in a template: template f(alias s, string file = __FILE__, size_t line = __LINE__) { import std.exception : enforce; import std.string : format; void g() {