Get TypeNames of Variadic Templates
Christian Köstlin
christian.koestlin at gmail.com
Sat Feb 2 08:10:58 PST 2013
Yes! very good idea!
I also added something like static assert(staticIndexOf!(T, Children) !=
-1); to get a compile time error when someone wants to get something
which is not there.
thanks
christian
On 2/2/13 14:13 , Philippe Sigaud wrote:
> 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