www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit template function overloading broken?

Here's the example.  Note that the first two calls which have the type 
explicitly specified work, and the second two don't.




struct S1 {
     void foo() { printf( "foo\n" ); }
}

struct S2 {
     void bar() { printf( "bar\n" ); }
}

typedef int HasFoo;
typedef int HasBar;

template SType( T ) {
     static if( is( typeof( T.foo ) ) )
         alias HasFoo SType;
     else static if( is( typeof( T.bar ) ) )
         alias HasBar SType;
     else
         alias void SType;
}

void doSomething( T, U : HasFoo = SType!(T) )( T val ) {
     val.foo();
}

void doSomething( T, U : HasBar = SType!(T) )( T val ) {
     val.bar();
}

void main()
{
     S1 s1;
     S2 s2;

     doSomething!(S1)( s1 );
     doSomething!(S2)( s2 );

     doSomething( s1 );
     doSomething( s2 );
}
Sep 01 2007