How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

rempas rempas at tutanota.com
Mon Oct 9 16:33:32 UTC 2023


Let's see the following example:

```d
import std.stdio;

static foreach(i; 0 .. 10) {
   mixin(create_fn!(i.stringof));
}

enum create_fn(string num) = `
   void function_`~ num ~`() { writeln("Hello from function `~ num 
~`!"); }
`;

void main() {
   function10();
}
```

I'm trying to create a series of function. There will be ten of 
them, and they will be called `function_0`, `function_1`, etc. 
However, in my example, "stringof" returns the character "i" 
itself and turns that into a string instead of getting its actual 
value (number).

Any ideas how I can achieve what I'm trying to achieve?


More information about the Digitalmars-d-learn mailing list