Compile time int to string conversion in BetterC

Ogi ogion.art at gmail.com
Fri Aug 19 08:50:26 UTC 2022


On Wednesday, 17 August 2022 at 10:38:33 UTC, Dennis wrote:
> I had the same problem, and came up with the following trick:
>
> ```D
> enum itoa(int i) = i.stringof;
>
> enum major = 3;
> enum minor = 2;
> enum patch = 1;
>
> enum versionString = itoa!major ~ "." ~ itoa!minor ~ "." ~ 
> itoa!patch;
>
> static assert(versionString == "3.2.1");
> ```

Nice! Thank you, I’ll use this.



More information about the Digitalmars-d-learn mailing list