fork(3) download
  1. #include <iostream>
  2.  
  3. namespace detail
  4. {
  5. template <typename T> struct foo;
  6.  
  7. template <typename T>
  8. struct foo<T*>
  9. {
  10. void operator()(const T* str) {std::cout << "ptr: " << str << std::endl;}
  11. };
  12.  
  13. template <typename T, std::size_t N>
  14. struct foo<T [N]>
  15. {
  16. void operator()(const T (&str)[N]) {std::cout << "arr: " << str << std::endl;}
  17. };
  18. }
  19.  
  20. template<typename T>
  21. void foo(const T& t)
  22. {
  23. detail::template foo<T>()(t);
  24. }
  25.  
  26. int main()
  27. {
  28. const char* ptr = "hello world";
  29. foo("hello world"); // arr
  30. foo(ptr); // ptr
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
arr: hello world
ptr: hello world