10

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?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
skydoor
  • 25,218
  • 52
  • 147
  • 201
  • This has been covered quite well already: http://stackoverflow.com/search?q=function+partial+specialization and http://www.google.com/search?q=function+template+partial+specialization provide abundant resources. – Potatoswatter Feb 07 '10 at 01:30

2 Answers2

10

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.

0

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.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123