20

Does anyone know whether, in C++11, function templates can be partially specialized?

0

2 Answers 2

15

No, they can't. The draft C++0x standard has a section (14.5.5) on class template partial specialisations, but no mention of function template partial specialisations.

4
-1

No; they were proposed as core language issue #229 (from n1295) but ultimately rejected (and quite rightly so, since overloading does the job).

3
  • 17
    I have to disagree with "quite rightly so". Overloading does not always do the job since we can't have overloads that differ only on return type. It would be nice if I could do something like the following, for example: template <class T, class U> T& Foo() { ... } template<class U> void Foo<void, U>() { ... } Oct 1, 2014 at 16:31
  • I agree overloading is not sufficient. Say I want to overload std::make_shared for a legacy C struct with custom create_* and destroy_* functions. A partial specialization would be very useful in this case.
    – AndyJost
    Oct 5, 2015 at 21:22
  • 4
    More disagreement to "quite rightly so": enable_if. If we could partially specialize functions, we could avoid clumsy hacks with tag helpers.
    – GreenScape
    Jun 1, 2016 at 10:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.