On Monday, 9 October 2023 at 16:33:32 UTC, rempas wrote:
However, in my example, "stringof" returns the character "i"
itself and turns that into a string instead of getting its
actual value (number).
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.