C++ 模板元编程-g++;吃了它,叮当不吃
有什么办法让两个编译器都满意吗 为此:C++ 模板元编程-g++;吃了它,叮当不吃,c++,metaprogramming,generic-programming,C++,Metaprogramming,Generic Programming,有什么办法让两个编译器都满意吗 为此: template<short value> struct static_signbits { enum { result = (!!(value & 0x8000) == !!(value & 0x4000)) ? (static_signbits<short(value << 1)>::result + 1) : 0 }; }; template<> struct static_s
template<short value>
struct static_signbits
{
enum { result = (!!(value & 0x8000) == !!(value & 0x4000)) ? (static_signbits<short(value << 1)>::result + 1) : 0 };
};
template<>
struct static_signbits<0>
{
enum
{
result = 15
};
};
模板
结构静态符号位
{
枚举{result=(!!(value&0x8000)=!!(value&0x4000))?(静态符号位这是因为clang不支持负数
error: non-type template argument is not a constant expression
enum { result = (!!(value & 0x8000) == !!(value & 0x4000)) ? (static_signbits<short(value << 1)>::result + 1) : 0 };
^~~~~~~~~~~~~~~~~
template<short value>
struct static_signbits
{
enum { result = (!!(value & 0x8000) == !!(value & 0x4000)) ? (static_signbits<(short)((unsigned)value << 1)>::result + 1) : 0 };
};