Annoyance with new integer promotion deprecations
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Feb 6 06:22:19 UTC 2018
On Tue, Feb 06, 2018 at 01:25:16AM +0000, Rubn via Digitalmars-d wrote:
[...]
> Maybe in the future this could be possible:
>
> static assert("Hello " ~ 10 ~ " world" == "Hello 10 world");
>
> It'd help with CTFE code, I find having to convert integers to strings
> a lot. This is cleaner syntax and don't rely on std.conv.to. So it
> doesn't need to be imported, I'm not sure if DMD uses an intrinsic for
> that as well. I hope it does but can't be certain.
No need to wait for the future, you can do this today:
enum toStr(alias X) = X.stringof;
enum x = 100;
pragma(msg, toStr!1);
pragma(msg, toStr!3.14159);
pragma(msg, "Hello " ~ toStr!10 ~ " world");
pragma(msg, "Hello " ~ toStr!x ~ " world");
Note, however, that this doesn't work in CTFE, only at template
expansion time.
T
--
Programming is not just an act of telling a computer what to do: it is also an act of telling other programmers what you wished the computer to do. Both are important, and the latter deserves care. -- Andrew Morton
More information about the Digitalmars-d
mailing list