我正在尝试使用 GCC 4.7 快照做一些类似的事情:
template <int n, int... xs>
struct foo {
static const int value = 0;
};
// partial specialization where n is number of ints in xs:
template <int... xs>
struct foo<sizeof...(xs), xs...> { // error: template argument ‘sizeof (xs ...)’
// involves template parameter(s)
static const int value = 1;
};
template <int... xs>
struct foo<sizeof(xs), xs...> { // This compiles fine. sizeof(xs) is sizeof int
// even though packs aren't expanded
static const int value = 2;
};
该错误很奇怪,因为在这种情况下, sizeof 而不是 sizeof... 起作用。两者似乎都可以在编译时轻松计算。
编译器是否正确,我无法使用sizeof...
在模板参数中进行专门化?
阅读后我将假设这是一个编译器问题这个帖子.
部分特化的非类型参数表达式不应涉及部分特化的模板参数,除非参数表达式是简单标识符。
哪个有争议here.
GCC 要么错误地解压参数包,要么评估sizeof
过早地。
对我提交的错误报告的回复可能会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)