【发布时间】:2019-03-10 15:58:56
【问题描述】:
有什么方法可以让两个编译器都满意吗?
为此:
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
};
};
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 };
^~~~~~~~~~~~~~~~~
显然对短片的演员阵容不满意?
显然,我可以改用 constexpr,但我还需要向后兼容 C++98
【问题讨论】:
标签: c++ metaprogramming generic-programming