Using double value in string template mixin
BBasile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Feb 26 03:37:32 PST 2016
On Friday, 26 February 2016 at 11:26:51 UTC, BBasile wrote:
> No you cannot because you would have to convert the values to
> string using std.conv.to or std.format.format(), but they don't
> work at compile time (see
> https://issues.dlang.org/show_bug.cgi?id=13568).
Erratum! Actually you can, example:
import std.stdio;
string foo(double a)()
{
return "auto value = " ~ a.stringof ~ ";";
}
void main(string[] args)
{
mixin(foo!0.1);
writeln(value); // 0.1
writeln(typeof(value).stringof); // double
}
So you have to use .stringof on the template argument.
Sorry for the previous answer.
More information about the Digitalmars-d-learn
mailing list