我想在模板类的函数中删除浮动到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标签