简体   繁体   English

使用可变参数模板的模板专业化

[英]Template specialization with variadic templates

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;
}

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. 这不会编译,第二个doStuff声明给我error: template-id 'doStuff<1u, int, bool>' for 'void doStuff(int, bool)' does not match any template declaration但它明确匹配第一个声明使用可变参数模板参数。

How to specialize variadic templates? 如何专门研究可变参数模板?

The syntax is correct (afaik, and clang++ accepts it), but your compiler is probably just not up2date yet. 语法是正确的(afaik,并且clang ++接受它),但你的编译器可能还没有up2date。

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) 如果你使用gcc,它的可变参数模板支持是非常不完整的,甚至最近的svn版本也不支持专业化(这就是你使用尖端技术时的情况,遗憾的是gcc只实现了一个非常早期不完整的可变参数模板提议,从那时起并没有跟上太多,而clang开始很晚,但相当完整)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM