#include <iostream>
struct A
{
bool f( int a ) { std::cout << "int" << std::endl; return true;};
bool f( int a, int b ) { std::cout << "two int" << std::endl; return true;};
bool f( float a ) {std::cout << "float" << std::endl; return true;};
bool f( float a, float b ) {std::cout << "two float" << std::endl; return true;};
};
template <typename T>
struct Type
{
typedef bool (A::*One)(T);
typedef bool (A::*Two)(T, T);
};
template <typename T, typename Type<T>::One F >
void run(A & a)
{
T tmp = 0;
(a.*F)(tmp);
}
int main(int argc, char ** argv )
{
A a;
run<int, &A::f>(a);
run<float, &A::f>(a);
return 0;
}
Problem lies with syntax of typename Type<T>::One F. If I specify the actual method pointer instead of using my typedef from Type it works fine (see here and here).
Is there a way to use those typedefs from Type as template arguments?
My current guess is that both IBM xlC and Sun CC have bugs.
The versions which give errors are probably confused by the use of
typenamein a template argument context but used to indicates that a dependant name is a type instead of introducing a type argument. Note that these compilers aren’t conforming and don’t demandtypenameto indicates that a dependant name is a type even in other contexts where it is needed (even for Sun CC versions where your code compile).