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
Tue Oct 10 13:52:19 UTC 2023


On Tuesday, 10 October 2023 at 05:32:52 UTC, Imperatorn wrote:
> If count < 10 then why not just
>
> ```d
> import std;
>
>     static foreach(c; "0123456789")
>     {
>       mixin(create_fn!(c));
>     }
>
>     enum create_fn(char num) = `
>       auto function_`~ num ~`()
>         => "Hello from function `~ num ~`!";
>     `;
>
>     void main()
>     {
>       assert(function_9() == "Hello from function 9!");
>     }
> ```

Thank you! Yeah, the most clean code wins for me, so I'll use 
yours (if it's open source, lol)! Thank you and have an amazing 
day!


More information about the Digitalmars-d-learn mailing list