我知道语言规范禁止功能模板的部分特化.
我想知道为什么禁止它的理由?它们没用吗?
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!
Run Code Online (Sandbox Code Playgroud) c++ language-design partial-specialization template-specialization function-templates
我知道下面的代码是类的部分特化:
template <typename T1, typename T2>
class MyClass {
…
};
// partial specialization: both template parameters have same type
template <typename T>
class MyClass<T,T> {
…
};
Run Code Online (Sandbox Code Playgroud)
另外我知道C++不允许函数模板部分特化(只允许完整).但是我的代码是否意味着我对一个/同一类型的参数有部分专业的函数模板?因为它适用于Microsoft Visual Studio 2010 Express!如果不是,那么请您解释部分专业化概念吗?
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
template <typename T1, typename T2>
inline T1 max (T1 const& a, T2 const& b)
{
return a < b ? b : a;
}
template <typename T>
inline T const& max (T const& a, T const& b)
{
return …Run Code Online (Sandbox Code Playgroud) c++ templates partial-specialization template-specialization
有谁知道,在C++ 11中,函数模板是否可以部分专用?