Get TypeNames of Variadic Templates
Christian Köstlin
christian.koestlin at gmail.com
Fri Feb 1 00:10:52 PST 2013
Hi,
i am trying to generate members for all types in a variadic class
template like this:
import std.stdio;
class Component(Children...) {
/// results eg. in public Component1 fComponent1;
static string createMembers() {
string res = "";
foreach (child; Children) {
res ~= "public " ~ child.stringof ~ " f" ~ child.stringof ~ ";\n";
}
return res;
}
mixin(createMembers());
}
class Component1 : Component!() {
}
class Component2 : Component!(Component1) {
}
int main(string[] args) {
writeln([ __traits(allMembers, Component2) ]);
return 0;
}
as you can see, Component2 now has a member called fComponent1.
My question is, is it possible to generate this with some mapping
algorithm, instead of writing this loop by hand?
regards
christian koestlin
More information about the Digitalmars-d-learn
mailing list