www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Comparing mixed expression and type tuples. How?

reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
import std.typetuple;

static assert( is( TypeTuple!( int, "a" ) == TypeTuple!( int, "a" ) );

The above code asserts. Is there some other way to compare mixed tuples,  
or should i roll my own comparison function?


-- 
Simen
May 25 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Simen kjaeraas Wrote:
 static assert( is( TypeTuple!( int, "a" ) == TypeTuple!( int, "a" ) );
Look for this problem in the digitalmars.D.learn group, because I have seen this problem recently solved here (I don't remember the solution, it was easy). Bye, bearophile
May 25 2010
parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
bearophile <bearophileHUGS lycos.com> wrote:

 Simen kjaeraas Wrote:
 static assert( is( TypeTuple!( int, "a" ) == TypeTuple!( int, "a" ) );
Look for this problem in the digitalmars.D.learn group, because I have seen this problem recently solved here (I don't remember the solution, it was easy).
Yeah. is( T == U ) only works for type tuples, though. Had to write my own comparison code. I'd recommend something like this be added to Phobos. template SameTuple( T... ) { template As( U... ) { static if ( T.length != U.length ) { enum As = false; } else static if ( T.length == 0 ) { enum As = true; } else static if ( T.length == 1 ) { enum As = is( T[0] == U[0] ) || T[0] == U[0]; } else { enum As = SameTuple!( T[1..$] ).As!( U[1..$] ) && is( T[0] == U[0] ) || T[0] == U[0]; } } } Usage: if ( SameTuple!( int, "a" ).As( int, "a" ) ) {} -- Simen
May 26 2010
next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Simen kjaeraas <simen.kjaras gmail.com> wrote:

 if ( SameTuple!( int, "a" ).As( int, "a" ) ) {}
Now if only someone would fix http://d.puremagic.com/issues/show_bug.cgi?id=242 -- Simen
May 26 2010
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Simen kjaeraas:

I'd recommend something like this be added to Phobos.<
Looks nice. There are many small bits of functionality like that that are missing still in Phobos and can be added. I suggest you to put that code in a bugzilla entry (otherwise I can do it myself) with a good unittest{} and if you want a ddoc comment too. Bye, bearophile
May 26 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
bearophile <bearophileHUGS lycos.com> wrote:

 Looks nice. There are many small bits of functionality like that that  
 are missing still in Phobos and can be added. I suggest you to put that  
 code in a bugzilla entry (otherwise I can do it myself) with a good  
 unittest{} and if you want a ddoc comment too.
Done: http://d.puremagic.com/issues/show_bug.cgi?id=4239 -- Simen
May 26 2010