Using double value in string template mixin

Dibyendu Majumdar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 26 03:13:08 PST 2016


On Friday, 26 February 2016 at 11:07:28 UTC, BBasile wrote:
> On Friday, 26 February 2016 at 11:03:43 UTC, Dibyendu Majumdar 
> wrote:
>> How do I use a double value in a mixin template that is 
>> generating string?
>
> Have you an example of what's failing right now to show ?

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 ~ ")";
}

MyT *t = mixin(MyTAlloc!(2,5.0));

Error: incompatible types for (("MyT_init(cast(MyT *) 
alloca(alloc_size(" ~ cast(immutable(char))2 ~ ")), " ~ 
cast(immutable(char))2 ~ ", ") ~ (5.00000)): 'string' and 'double'


More information about the Digitalmars-d-learn mailing list