Hi Philippe,
wonderful solution. I also added
T get(T)() {
return components[staticIndexOf!(T, Children)];
}
to the class to get the Children out by type (works as long as there is
only one child of each type in the tuple).
thanks a lot!!!
christian
On 2/1/13 16:04 , Philippe Sigaud wrote:
Hi Christian,
My question is, is it possible to generate this with some mapping algorithm,
instead of writing this loop by hand?
You can create a tuple:
class Component(Children...) {
Children components; //<- Here
this() {}
static if (Children.length> 0)
this(Children args)
{
components = args;
}
}
void main()
{
auto c = new Component!(int, double, Component!(string));
writeln(c.components);
c.components[0] = 1;
c.components[1] = 3.14159;
c.components[2] = new Component!(string)("abc");
writeln(c.components);
writeln(c.components[2].components);
}