开发者

partial specialization of function template

开发者 https://www.devze.com 2022-12-19 22:19 出处:网络
Can anybody explain w开发者_StackOverflow中文版hy partial specialization is not valid for function template but it\'s fine for class template.

Can anybody explain w开发者_StackOverflow中文版hy 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消