digitalmars.D.learn - Comparing mixed expression and type tuples. How?
- "Simen kjaeraas" <simen.kjaras gmail.com> May 25 2010
- bearophile <bearophileHUGS lycos.com> May 25 2010
- bearophile <bearophileHUGS lycos.com> May 26 2010
- "Simen kjaeraas" <simen.kjaras gmail.com> May 26 2010
- "Simen kjaeraas" <simen.kjaras gmail.com> May 26 2010
- "Simen kjaeraas" <simen.kjaras gmail.com> May 26 2010
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
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
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
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
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
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









bearophile <bearophileHUGS lycos.com> 