fork(9) 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_pointer<T>::value >::type* = 0)
  14. {
  15. std::cout << "insert pointer" << std::endl;
  16. }
  17.  
  18. template<class T=Object>
  19. void insert(T t, typename std::enable_if<!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(new MyClass());
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
insert non-pointer
insert pointer