我想知道是否有可能扩展SFINAE方法来检测一个类是否具有某个成员函数(如下所述:
"在C++中是否有一种技术可以知道一个类是否具有给定签名的成员函数?" 检查类是否具有给定签名的成员函数
)支持模板化成员函数?例如,为了能够检测以下类中的函数foo:
struct some_class {
template < int _n > void foo() { }
};
Run Code Online (Sandbox Code Playgroud)
我认为有可能为foo的特定实例化做这个(例如检查是否void foo< 5 >()是成员),如下所示:
template < typename _class, int _n >
class foo_int_checker {
template < typename _t, void (_t::*)() >
struct sfinae { };
template < typename _t >
static big
test( sfinae< _t, &_t::foo< _n > > * );
template < typename _t >
static small
test( ... );
public:
enum { value = sizeof( test< _class >( 0 …Run Code Online (Sandbox Code Playgroud)