Annoyance with new integer promotion deprecations

Nick Sabalausky (Abscissa) SeeWebsiteToContactMe at semitwist.com
Wed Feb 7 00:00:05 UTC 2018


On 02/06/2018 01:22 AM, H. S. Teoh wrote:
> 
> 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.
> 

There's an easier way that does work in CTFE:

---------------------------

import std.conv;

enum x = 100;
pragma(msg, 1.text);
pragma(msg, "Hello " ~ 10.text ~ " world");
pragma(msg, "Hello " ~ x.text ~ " world");

enum y = 2.text;
pragma(msg, y);

//pragma(msg, 3.14159.text); // Ugh, ok, floats don't work though :(


More information about the Digitalmars-d mailing list