#include<iostream>
#include<string>
using namespace std;
namespace bite
{
//1. 非类型模板参数
// 定义一个模板类型的静态数组
template<class T, size_t N = 10>
class array
{
public:
T& operator[](size_t index) { return _array[index]; }
const T& operator[](size_t index)const { return _array[index]; }
size_t size()const { return _size; }
bool empty()const { return 0 == _size; }
private:
T _array[N];
size_t _size;
};
}
//2.函数模版特化
namespace hanshumobantehua{
template<class T>
bool Less(T left, T right) {
return left < right;
}
template<>//函数模版特化
bool Less<int*>(int* left, int* right) {
cout << "int* left int* right" << endl;
return *left < *right;
}
}
//3.类模版特化
template<class T1,class T2>
class Date {
public:
Date() { cout << "Date<T1 T2>"<<endl; }
};
template<>//类模版特化 全特化
class Date<int, double> {
public:
Date() { cout << "Date<int double>"<<endl; }
};
template<class T>//偏特化 1.对类型的进一步限制
class Date<T*,T*> {
public:
Date() { cout << "Date<T* T*>" << endl; }
};
template<class T> //2.特化部分参数
class Date<T, double> {
public:
Date() { cout << "Date<T double>" << endl; }
};
template<class T>
class Date<T*, double> {
public:
Date() { cout << "Date<T* double>" << endl; }
};//偏特化 1.对类型的进一步限制 2.特化部分参数
int main() {
int a = 1, b = 2;
int* pa =&b, *bp =&a;
Date<double, string> d1;
Date<int*, double> d2;
//Date<int, int> d2;
//Date<int*,int*>d3;
//Date<double, double> d4;
}