Using double value in string template mixin

BBasile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 26 03:26:51 PST 2016


On Friday, 26 February 2016 at 11:13:08 UTC, Dibyendu Majumdar 
wrote:
> I am trying something like this:
>
> template MyTAlloc(int n_vars, double v) {
> const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~ 
> n_vars ~ ")), " ~ n_vars ~ ", " ~ v ~ ")";

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).

Ideally like this:

template MyTAlloc(int n_vars, double v) {
const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~
to!string(n_vars) ~ ")), " ~ to!string(n_vars) ~ ", " ~ 
to!string(v) ~ ")";

But you can try with regular templates or mixin templates.





More information about the Digitalmars-d-learn mailing list