简体   繁体   English

功能模板的部分特化

[英]partial specialization of function template

Can anybody explain why partial specialization is not valid for function template but it's fine for class template. 任何人都可以解释为什么部分特化对于函数模板无效,但它适用于类模板。

I understand partial specialization might make the compiler get confused with function overloading, but I still need more information to make me totally understand. 我理解部分特化可能会使编译器与函数重载混淆,但我仍然需要更多信息让我完全理解。 Can anybody offer me some neat examples? 有人可以给我一些简洁的例子吗?

Getting confused is enough of a reason, in this case. 在这种情况下,混淆就足够了。

And there's an existing alternative solution: overloading. 还有一个现有的替代解决方案:重载。 The committee spent a lot of effort (it seems to me, I wasn't there) getting function overload resolution working for templates, and surely part of the reason for that included not having to solve the less-general, hard problem of function template partial specialization. 委员会花了很多精力(在我看来,我不在那里)获取函数重载解析工作模板,当然部分原因包括不必解决功能模板的一般性,难以解决的问题部分专业化。

Now, I'm not an expert but I think the answer to the first part is that partial function specialisation would conflict (and be partially redundant) with function overloading. 现在,我不是专家,但我认为第一部分的答案是部分函数特化会与函数重载冲突(并且部分冗余)。 As for the second part, you can use a template struct that serves as a container for the thing you want to partially specialise. 至于第二部分,您可以使用模板结构作为要部分特化的事物的容器。

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

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