Get TypeNames of Variadic Templates

Philippe Sigaud philippe.sigaud at gmail.com
Fri Feb 1 07:04:37 PST 2013


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


More information about the Digitalmars-d-learn mailing list