Consider a set of functions like
template< class Fun >
void A( const Fun& )
{
}
template< class Fun >
void B( const Fun& )
{
}
template< class Fun >
void C( const Fun& )
{
}
designed to take function types as arguments. Then, this is perfectly ok:
template< class T >
void Func( const T& )
{
}
A( Func< int > );
B( Func< int > );
C( Func< int > );
Now I wanted to get rid of repeating the int
temaplate argument so I tried this:
template< class T >
struct Helper
{
template< template< class > class Fun >
static void A( Fun< T >& f )
{
A( f );
}
template< template< class > class Fun >
static void B( Fun< T >& f )
{
B( f );
}
...
};
typedef Helper< int > IntHelper;
IntHelper::A( Func ); //error
IntHelper::B( Func ); //
IntHelper::C( Func ); //
however this fails to compile on gcc 4.5.1 ('error: no matching function for call to 'Helper<int>::A(<unresolved overloaded function type>)'
) and MSVC10 (cannot use function template 'void Func(const T &)' as a function argument
and could not deduce template argument for 'overloaded function type' from 'overloaded function type'
).
Can someone explain why exactly, and is there a way around this?
edit ok I understand why it is not possible now; for the answers containing a workaround: in the actual code there are a lot of different Func
s, say 100, while there's only about 6 function like A, B and C...