可能重复:
Is it possible to write a C++ template to check for a function's existence?
我有兴趣找到一些SFINAE驱动的表达式,它允许我检测成员函数的存在并相应地处理它,la:
template <typename T>
int maybe_member(T& x, {{sfinae_1}})
{
return x.maybe_member();
}
template <typename T>
int maybe_member(T& x, {{sfinae_2}})
{
std::cerr << "This T does not implement maybe_member.\n";
return 1;
}
int main()
{
my_type_t instance;
return maybe_member(instance);
}
一系列问题: