https://www.zhihu.com/question/54713079/answer/140746689
#include <iostream>
using namespace std;
template<class T>
struct foo
{
using type = T;
};
template<class T>
struct bar
{
};
template<class T>
struct ty_sfinae_helper
{
using type = void;
};
template<class T, class U = void>
struct ty_has_type
{
const static int value = 0;
};
template<class T>
struct ty_has_type<T, typename T::type>
{
const static int value = 1;
};
template<class T>
struct ty_has_type<T, typename ty_sfinae_helper<typename T::type>::type>
{
const static int value = 2;
};
template<class...>
using void_t = void;
template<class, class = void>
struct has_type : false_type
{
};
template<class T>
struct has_type<T, void_t<typename T::type>> : true_type
{
};
int main()
{
cout << ty_has_type<foo<int>>::value << endl;
cout << ty_has_type<bar<int>>::value << endl;
cout << has_type<bar<int>>::value << endl;
return 0;
}
sfinae
原文:http://www.cnblogs.com/abelian/p/6286790.html