fork(1) download
  1. #include <type_traits>
  2. #include <iostream>
  3. class MyClass
  4. {
  5. };
  6.  
  7. template <typename Object>
  8. class List
  9. {
  10. public:
  11.  
  12. template<class T=Object>
  13. void insert(T t, typename std::enable_if<std::is_same<T,Object>::value&&std::is_pointer<T>::value >::type* = 0)
  14. {
  15. std::cout << "insert pointer" << std::endl;
  16. }
  17.  
  18. template<class T=Object>
  19. void insert(const T& t, typename std::enable_if<std::is_same<T,Object>::value&&!std::is_pointer<T>::value >::type* = 0)
  20. {
  21. std::cout << "insert non-pointer" << std::endl;
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. MyClass a;
  28.  
  29. List<MyClass> lst;
  30. List<MyClass*> plst;
  31.  
  32. lst.insert(a);
  33. // plst.insert(a); // compiler error
  34.  
  35. // lst.insert(new MyClass()); // compiler error
  36. plst.insert(new MyClass());
  37.  
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
insert non-pointer
insert pointer