1.什么是SFINAE?
请看下面的链接 SFINAE
2.如果使用SFINAE检查类或者结构体是否定义某个成员函数?
这里直接给出代码,以operator()函数为例
#include <type_traits>
#include <iostream>
struct Hello
{
void operator()() { std::cout << "Hello World" << std::endl; }
};
struct Generic {};
#define HAS_MEM_FUNC(FunctionName, HelperClassName) \
template<typename T> \
struct HelperClassName { \
typedef char one; \
typedef long two; \
template <typename C> static one test(decltype(&C::FunctionName)); \
template <typename C> static two test(...); \
public: \
enum { value = sizeof(test<T>(0)) == sizeof(char) }; \
}
HAS_MEM_FUNC(operator(), hasOperatorParentheses);
template<class T, class Enable = void>
class A
{
public: