【发布时间】:2016-11-15 17:35:37
【问题描述】:
在编译以下代码期间检查正确性(用于从从右到左从 1 开始的索引从类型列表中选择类型的元函数)在 GCC 上失败,而 clang em> 接受此代码:
#include <cstdlib>
template< std::size_t i, typename ...types >
struct at_index
{
};
template< typename first, typename ...rest >
struct at_index< (1 + sizeof...(rest)), first, rest... >
{
using type = first;
};
template< std::size_t i, typename first, typename ...rest >
struct at_index< i, first, rest... >
: at_index< i, rest... >
{
};
int main()
{
}
哪个编译器是正确的?
GCC 错误信息:
error: template argument '(1 + sizeof... (rest))' involves template parameter(s)
struct at_index< (1 + sizeof...(rest)), first, rest... >
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我认为sizeof... 运算符中参数包的类型不应该被解析为符号名称的某些部分。因此,这里不应该存在名称修改问题。
这是允许上述代码的 clang 扩展吗?
【问题讨论】:
标签: c++ c++11 c++14 language-lawyer variadic-templates