我可以使用像foo <T ...,int,U ...>这样的模式来部分地专门化模板吗?

R. *_*des 6 c++ templates variadic-templates c++11

如果可以,则可以索引到可变参数模板参数包而不进行递归.但是,海湾合作委员会拒绝接受我的部分专业化:

template <int I, typename List>
struct element_impl;

template <typename... TL, int... IL, typename T, int I, typename... TR, int... IR>
struct element_impl<I, typelist<pair<TL,IL>..., pair<T,I>, pair<TR,IR>...>> {
    typedef T type;
};
Run Code Online (Sandbox Code Playgroud)

prog.cpp:实例化' element<0, typelist<int, double, char, float, long int> >':
prog.cpp:52:34:从这里实例化
prog.cpp:47:79:错误:无效使用不完整类型' struct element_impl<0, typelist<pair<int, 0>, pair<double, 1>, pair<char, 2>, pair<float, 3>, pair<long int, 4> >'

是GCC有缺陷的,还是我忽略了可变参数模板的一些限制?

Joh*_*itb 5

规范在14.8.2.5p9说

如果P具有包含<T>or 的形式<i>,则将Pi相应模板参数列表的每个参数与相应模板参数列表P的对应参数Ai进行比较A.如果模板参数列表P包含不是最后一个模板参数的包扩展,则整个模板参数列表是非推导的上下文.

typelist<T>不幸的是,你匹配这种模式.