Comparing mixed expression and type tuples. How?

Simen kjaeraas simen.kjaras at gmail.com
Wed May 26 08:21:56 PDT 2010


bearophile <bearophileHUGS at 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


More information about the Digitalmars-d-learn mailing list