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:54:12 UTC 2023
On Tuesday, 10 October 2023 at 11:45:25 UTC, Dennis wrote:
> The result of `.stringof` is implementation defined, it can be
> used for debugging but don't make your program's semantics
> depend on the output of it.
>
> ...
>
> ...
>
> ...That being said, this trick can be used to convert an
> integer to string at compile time:
>
>
> ```D
> enum itoa(int i) = i.stringof;
>
> static foreach(i; 0 .. 10) {
> mixin(create_fn!(itoa!i));
> }
> ```
>
> Technically not reliable, but I don't expect integers to ever
> get printed differently than a string of base 10 digits.
Thank you! It is great and works great. I will however use the
example from Imperatorn as it does not use ".stringof". Have an
amazing day!
More information about the Digitalmars-d-learn
mailing list