相关疑难解决方法(0)

为什么总是调用`static_assert`?

如果USE_STATIC_ASSERT0,则按预期工作(从列表中获取索引类型).如果1 static_assert()总是跳闸.我本以为static_assert()只有当所有人typename都筋疲力尽时才会发生.为什么不是这样?

#define USE_STATIC_ASSERT 1
template <unsigned int I, typename ...Ts>
struct items;

template <typename T, typename ...Ts>
struct items<0, T, Ts...>
{
    typedef T type;
};

template <unsigned int I, typename T, typename ...Ts>
struct items<I, T, Ts...> : items<I-1, Ts...>
{
};

#if USE_STATIC_ASSERT
template <unsigned int I>
struct items<I>
{
    static_assert(false, "Ran out of Ts.");
};
#endif


int main()
{
    cout << is_same<float, items<1, int, float, double>::type>::value << …
Run Code Online (Sandbox Code Playgroud)

c++ static-assert c++11

0
推荐指数
1
解决办法
192
查看次数

标签 统计

c++ ×1

c++11 ×1

static-assert ×1