함수 템플릿의 명시적 특수화
함수 템플릿을 사용하면 특정 형식에 대한 함수 템플릿의 명시적 특수화(재정의)를 제공하여 해당 형식에 대한 특별한 동작을 정의할 수 있습니다. 예를 들면 다음과 같습니다.
template<> void MySwap(double a, double b);
이 선언으로 double 변수에 대한 다른 함수를 정의할 수 있습니다. 비템플릿 함수와 마찬가지로, 표준 형식 변환(예: float 형식의 변수를 double로 확장)이 적용됩니다.
예제
// explicit_specialization.cpp
template<class T> void f(T t)
{
};
// Explicit specialization of f with 'char' with the
// template argument explicitly specified:
//
template<> void f<char>(char c)
{
}
// Explicit specialization of f with 'double' with the
// template argument deduced:
//
template<> void f(double d)
{
}
int main()
{
}