Base interfaces tuple

John C johnch_atms at hotmail.com
Sat Mar 15 08:19:24 PDT 2008


Jarrett Billingsley Wrote:

> "John C" <johnch_atms at hotmail.com> wrote in message 
> news:frgcqg$10kl$1 at digitalmars.com...
> 
> > BaseTypeTuple from std.traits seems to be the starting point, and 
> > recursively calling that template gets successive base types, but putting 
> > that together into a single template has defeated me. Anyone accomplished 
> > this?
> 
> Here's a Tango-y version:
> 
> import tango.core.Traits;
> 
> template AllBasesImpl(T...)
> {
>   static if(T.length == 0)
>     alias Tuple!() AllBasesImpl;
>   else
>     alias Tuple!(T[0], AllBasesImpl!(BaseTypeTupleOf!(T[0])), 
> AllBasesImpl!(T[1 .. $])) AllBasesImpl;
> }
> 
> template AllBases(T)
> {
>   alias Unique!(AllBasesImpl!(BaseTypeTupleOf!(T))) AllBases;
> }
> 
> I believe the Phobos version would be something like this:
> 
> import std.typetuple;
> import std.traits;
> 
> template AllBasesImpl(T...)
> {
>   static if(T.length == 0)
>     alias TypeTuple!() AllBasesImpl;
>   else
>     alias TypeTuple!(T[0], AllBasesImpl!(BaseTypeTuple!(T[0])), 
> AllBasesImpl!(T[1 .. $])) AllBasesImpl;
> }
> 
> template AllBases(T)
> {
>   alias NoDuplicates!(AllBasesImpl!(BaseTypeTuple!(T))) AllBases;
> } 
> 
> 

Thanks Jarrett - works a treat.


More information about the Digitalmars-d-learn mailing list