Implicit template function overloading broken?

Sean Kelly sean at f4.ca
Sat Sep 1 09:40:49 PDT 2007


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 );
}



More information about the Digitalmars-d mailing list