Get TypeNames of Variadic Templates

Philippe Sigaud philippe.sigaud at gmail.com
Sat Feb 2 05:13:45 PST 2013


On Fri, Feb 1, 2013 at 11:04 PM, Christian Köstlin
<christian.koestlin at gmail.com> wrote:
> 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).

Indeed, that's easier for the user this way.
In that case, you might want to either return a tuple of one or more
type (when there is more than one of a given type) or put a
restriction on Components so it's only a set of types.

Maybe with:

... if(NoDuplicates!(Children).length == Children.length)

See http://dlang.org/phobos/std_typetuple.html#.NoDuplicates


Then, when you're feeling masochistic, the next step is to allow
assignments from other Components with a permutation of children,
because Component!(int,double) is not much different from
Components!(double, int)

:)


More information about the Digitalmars-d-learn mailing list