我使用了" 有没有办法测试C++类是否有默认构造函数(编译器提供的类型特征除外)? "的代码.
我稍微修改它以适应我的所有测试用例:
template< class T >
class is_default_constructible {
typedef int yes;
typedef char no;
// the second version does not work
#if 1
template<int x, int y> class is_equal {};
template<int x> class is_equal<x,x> { typedef void type; };
template< class U >
static yes sfinae( typename is_equal< sizeof U(), sizeof U() >::type * );
#else
template<int x> class is_okay { typedef void type; };
template< class U >
static yes sfinae( typename is_okay< sizeof U() >::type …Run Code Online (Sandbox Code Playgroud)