小编Bla*_*kHC的帖子

为什么使用两个sizeofs来检查一个类是否是默认可构造的,但是一个不是?

我使用了" 有没有办法测试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)

c++ templates metaprogramming

19
推荐指数
1
解决办法
1005
查看次数

标签 统计

c++ ×1

metaprogramming ×1

templates ×1