On Friday, 13 December 2013 at 13:23:24 UTC, Mike James wrote:
On Friday, 13 December 2013 at 12:09:59 UTC, John Colvin wrote:
On Friday, 13 December 2013 at 11:40:35 UTC, Mike James wrote:
Hi,

Is it possible to pass a string array to a string mixin e.g

template GenSomething(string foo, string[] bar){
some_kind_of_foreach(br: bar) {
  const char[] foo ~ br ~ ";\n";
}
}

and call:

mixin(GenSomething!("A", ["B", "C", "D"]));

would generate:

A.B;
A.C;
A.D;

Regards,

-=mike=-

CTFE is your friend here.

string genSomething(string foo, string[] bar) {
 string result;
 foreach(br: bar) {
   result ~= foo ~ '.' ~ br ~ ";\n";
 }
}

mixin(genSomething("A", ["B", "C", "D"]));

Thanks - that worked a treat (just needed a 'return result;').

Regards,

-=mike=-

woops, forgot that :)

Reply via email to