#include <type_traits>
#include <iostream>
class MyClass
{
};
template <typename Object>
class List
{
public:
template<class T=Object>
void insert(T t, typename std::enable_if<std::is_same<T,Object>::value&&std::is_pointer<T>::value >::type* = 0)
{
std::cout << "insert pointer" << std::endl;
}
template<class T=Object>
void insert(const T& t, typename std::enable_if<std::is_same<T,Object>::value&&!std::is_pointer<T>::value >::type* = 0)
{
std::cout << "insert non-pointer" << std::endl;
}
};
int main()
{
MyClass a;
List<MyClass> lst;
List<MyClass*> plst;
lst.insert(a);
// plst.insert(a); // compiler error
// lst.insert(new MyClass()); // compiler error
plst.insert(new MyClass());
return 0;
}
CSNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KCSNpbmNsdWRlIDxpb3N0cmVhbT4KCWNsYXNzIE15Q2xhc3MKCXsKCX07CgkKCXRlbXBsYXRlIDx0eXBlbmFtZSBPYmplY3Q+CgljbGFzcyBMaXN0Cgl7CglwdWJsaWM6CgkKCQl0ZW1wbGF0ZTxjbGFzcyBUPU9iamVjdD4KCQl2b2lkIGluc2VydChUIHQsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPHN0ZDo6aXNfc2FtZTxULE9iamVjdD46OnZhbHVlJiZzdGQ6OmlzX3BvaW50ZXI8VD46OnZhbHVlID46OnR5cGUqID0gMCkgCgkJewoJCSAgICBzdGQ6OmNvdXQgPDwgImluc2VydCBwb2ludGVyIiA8PCBzdGQ6OmVuZGw7CgkJfQoJCQoJCXRlbXBsYXRlPGNsYXNzIFQ9T2JqZWN0PgoJCXZvaWQgaW5zZXJ0KGNvbnN0IFQmIHQsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPHN0ZDo6aXNfc2FtZTxULE9iamVjdD46OnZhbHVlJiYhc3RkOjppc19wb2ludGVyPFQ+Ojp2YWx1ZSA+Ojp0eXBlKiA9IDApIAoJCXsKCQkgICAgc3RkOjpjb3V0IDw8ICJpbnNlcnQgbm9uLXBvaW50ZXIiIDw8IHN0ZDo6ZW5kbDsKCQ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