#include <iostream>
template<int T> class Int2Type {
enum {value = T};
};
class ST{};
template<typename T, bool isPolymophic>
class NiftyContainer{
public:
void DoSomeThing(T* obj) {
this->DoSomeThing(obj, Int2Type<isPolymophic>());
}
private:
void DoSomeThing(T* obj, Int2Type<true>) {
std::cout<<"polymophic"<<std::endl;
}
void DoSomeThing(T* obj, Int2Type<false>) {
std::cout<<"no polymophic"<<std::endl;
}
};
void Test(){
ST st;
NiftyContainer<ST, true> nt;
nt.DoSomeThing(&st);
}
template<typename T, typename Q>
void Print(T* t, Q q) {
std::cout<<"template function 重载1"<<std::endl;
}
template<typename T>
void Print(T* t, int i) {
std::cout<<"template function 重载2"<<std::endl;
}
void Test1(){
Print("hello", 2);
Print("hello", "world");
}
template<typename T> class Type2Type{ typedef T NewDefinedType;};
template<typename T, typename Q>
T* CreateObj(Q q, Type2Type<T>) {
std::cout<<q<<std::endl;
return new T(q);
}
template<typename Q>
int* CreateObj(Q q, Type2Type<int>) {
std::cout<<q<<std::endl;
return new int(q);
}
void Test2(){
std::string* pstr = CreateObj<std::string, std::string>("hello", Type2Type<std::string>());
int * i = CreateObj<int>(10, Type2Type<int>());
}
int main() {
Test();
return 0;
}