Comparing Two Type Tuples

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Mon Apr 5 01:08:49 PDT 2010


On Mon, 5 Apr 2010 02:59:15 +0000 (UTC), BCS <none at anon.com> wrote:
> 
> Hello Daniel,
> 
> > Heya ppl!
> > 
> > I was wondering how could I write a function that takes two Type
> > Tuples as arguments and returns true if they are match.
> > 
> > Could anyone help me with this?
> > 
> > Thanks!
> >
> 
> here is my untested vertion:
> 
> template Compare(T...)
> {
>     template With(U...)
>     {
>         static if(T.length != U.lenght) const bool With = false;
>         else static if(T.length == 0) const bool With = true;
>         else static if(is(T[0] == U[0])) const bool With = Compare!(T[1..$]).With!(U[1..$]);
>         else const bool With = false;
>     }
> }
> 
> use like: Compare!(int, float, myStruct).With(alias1,alias2,typeArg)
>  

Definitely a lot cleaner. I'm curious, though... is there a reason to 
avoid is(T == U)?


More information about the Digitalmars-d-learn mailing list