AFAIK 在 C++0x 中发生了变化。
我想这只是一个疏忽(考虑到您总是可以通过将函数作为static
类的成员来使用更详细的代码来获得部分专业化效果)。
如果有,您可以查找相关的 DR(缺陷报告)。
编辑:检查这一点,我发现其他人也相信这一点,但没有人能够在标准草案中找到任何这样的支持。这个 SO 线程似乎表明C++0x 不支持函数模板的部分特化。
编辑2:只是我所说的“将函数作为static
类的成员”的一个例子:
#include <iostream>
using namespace std;
// template<typename T, typename U> void f() {} //allowed!
// template<> void f<int, char>() {} //allowed!
// template<typename T> void f<char, T>() {} //not allowed!
// template<typename T> void f<T, int>() {} //not allowed!
void say( char const s[] ) { std::cout << s << std::endl; }
namespace detail {
template< class T, class U >
struct F {
static void impl() { say( "1. primary template" ); }
};
template<>
struct F<int, char> {
static void impl() { say( "2. <int, char> explicit specialization" ); }
};
template< class T >
struct F< char, T > {
static void impl() { say( "3. <char, T> partial specialization" ); }
};
template< class T >
struct F< T, int > {
static void impl() { say( "4. <T, int> partial specialization" ); }
};
} // namespace detail
template< class T, class U >
void f() { detail::F<T, U>::impl(); }
int main() {
f<char const*, double>(); // 1
f<int, char>(); // 2
f<char, double>(); // 3
f<double, int>(); // 4
}