首页 > 其他 > 详细

sfinae

时间:2017-01-15 11:53:15      阅读:190      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!