小编s0n*_*b0k的帖子

删除C++模板类中的性能警告


我想在模板类的函数中删除浮动到bool转换性能警告,boost::enable_if在这种情况下感觉有点过分.

有没有办法在编译时检查模板的类型,然后根据类型使用适当的转换?

    T val;
    float val2;
    val = (T)(val+val2); // warning here for objects of type bool
Run Code Online (Sandbox Code Playgroud)


我想要这样的东西:

    #if (boost::is_same<CType, bool>::value == true)
        val = (val+val2)!=0;
    #else
        val = (T)(val+val2);
    #endif
Run Code Online (Sandbox Code Playgroud)


我不想只是禁用警告.

编辑:添加了visual studio标签

c++ templates boost compiler-warnings visual-studio

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

标签 统计

boost ×1

c++ ×1

compiler-warnings ×1

templates ×1

visual-studio ×1