SFINAE , , , ( ) , .
, decltype(T().apply<0u>(double())) decltype(T().template apply<0u>(double())), T() . : T().apply<0u>, T, apply < .? apply -, < . OTOH apply (, ), < "". , . , , , apply: . .template ( ->template ::template): , , , , , shouldn ' t - .
, , , g++ 4.5.0 -std=c++0x:
#include <iostream>
template < class T >
decltype( T().template apply< 0u >( double() ) ) f( T &t )
{
return t.template apply< 0u >( 5. );
}
const char *f( ... )
{
return "no apply<>";
}
class A {
public:
template < unsigned >
int apply( double d )
{
return d + 10.;
}
};
class B {};
int main()
{
A a;
std::cout << f( a ) << std::endl;
B b;
std::cout << f( b ) << std::endl;
}
:
15
no apply<>
, .template f(), :
no apply<>
no apply<>
class A, apply. SFINAE !