how to achieve C's Token Pasting (##) Operator to generate variable name in D?

mw mingwu at gmail.com
Sat May 30 22:06:30 UTC 2020


I want to generate a new symbol (new variable name) from existing 
one: e.g. in C:


$ cat t.c
--------------------------------------------
#define f(x) _##x

int main() {
   int f(x) = 3;
   return _x;
}

$ make t
cc     t.c   -o t
$ ./t
$ echo $?
3
--------------------------------------------

I wonder how to do this in D? using template / mixin? traits?

Can you show me an example?

Thanks.


More information about the Digitalmars-d-learn mailing list