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.



Reply via email to