Compile time int to string conversion in BetterC

Paul Backus snarwin at gmail.com
Thu Aug 18 22:00:06 UTC 2022


On Wednesday, 17 August 2022 at 11:38:31 UTC, Steven 
Schveighoffer wrote:
> On 8/17/22 6:38 AM, Dennis wrote:
>> On Wednesday, 17 August 2022 at 08:44:30 UTC, Ogi wrote:
>>> Maybe I’m missing something?
>> 
>> I had the same problem, and came up with the following trick:
>> 
>> ```D
>> enum itoa(int i) = i.stringof;
>> ```
>
> I have the same thing in my code:
>
> ```d
> enum intStr(int x) = x.stringof;
> ```

I merged a version of this into Phobos (for internal use):

https://github.com/dlang/phobos/blob/v2.100.1/std/conv.d#L5986-L5987

It also comes with a unit test, so we don't get surprise breakage 
if the behavior of `.stringof` ever changes.


More information about the Digitalmars-d-learn mailing list