Does anyone know whether, in C++11, function templates can be partially specialized?
2 Answers
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.
-
-
@DeadMG: Yes, I'm referring to the draft C++0x standard, open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3092.pdf Sep 15, 2010 at 11:08
-
FYI: The latest draft is now N3126 [Warning: Big PDF]. The answer isn't different in the latest draft. Sep 15, 2010 at 11:20
-
No; they were proposed as core language issue #229 (from n1295) but ultimately rejected (and quite rightly so, since overloading does the job).
-
17I 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.– AndyJostOct 5, 2015 at 21:22
-
4More disagreement to "quite rightly so":
enable_if
. If we could partially specialize functions, we could avoid clumsy hacks with tag helpers. Jun 1, 2016 at 10:40