Comparing Two Type Tuples

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Mon Apr 5 19:16:47 PDT 2010


On Mon, 5 Apr 2010 15:47:10 +0000 (UTC), BCS <none at anon.com> wrote:
> 
> Hello Justin Spahr-Summers,
> 
> > 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)?
> > 
> 
> I dind't know it worked?

It seemed to when I tested the snippet that I sent, but it might've just 
been luck of the draw, and in reality fail silently on certain edge 
cases. I'm really not sure.


More information about the Digitalmars-d-learn mailing list