小编Dan*_*iel的帖子

使用sfinae来测试命名空间成员的存在

我试图弄清楚是否有可能使用sfinae来测试命名空间成员的存在.谷歌相当沉默.我尝试了以下代码,但它失败了.

namespace xyz{
 struct abc{};
}

struct abc{};

struct test_xyz{ 
 typedef char yes;
 typedef struct{ char a[2]; } no;

 template <class C> static yes test(xyz::C = xyz::C()); //lets assume it has default constructor
 template <class C> static no test(...);

 const bool has_abc = sizeof(test_xyz::test<abc>()) == sizeof(yes);
};
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

问候,

c++ templates namespaces sfinae

5
推荐指数
1
解决办法
1139
查看次数

标签 统计

c++ ×1

namespaces ×1

sfinae ×1

templates ×1