问题描述
template <size_t size, typename ...Params>
void doStuff(Params...) {
}
template <>
void doStuff<size_t(1), int, bool>(int, bool) {
}
int main(int, char**) {
doStuff<1,int,bool>(1, false);
return 0;
}
这不编译,第二个doStuff声明给我 error:template-id'doStuff< 1u,int,bool>'for'void doStuff(int,bool)'不匹配任何模板声明
This doesn't compile, the second doStuff declaration gives me error: template-id ‘doStuff<1u, int, bool>’ for ‘void doStuff(int, bool)’ does not match any template declaration
but it clearly matches the first declaration with variadic template arguments.
如何专门化可变参数模板?
How to specialize variadic templates?
推荐答案
是正确的(afaik和clang ++接受它),但是你的编译器可能只是没有up2date。
The syntax is correct (afaik, and clang++ accepts it), but your compiler is probably just not up2date yet.
如果你使用gcc,其可变模板支持是不完全的,甚至最近的svn版本不支持专业化(这就是它是如何是当你使用出血边缘技术,并且悲伤地gcc实现只有一个非常早的不完全可变模板提案,从那时起没有跟上,而ang开始很晚,但很漂亮)
If you use gcc, its variadic template support is quite incomplete, and even very recent svn versions don't support specialization yet (That is just how it is when you use bleeding edge technology, and sadly gcc implemented only a very early incomplete variadic template proposal and since then didn't keep up much, while clang started pretty late, but got pretty complete)
这篇关于可变模板的模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!