fork(6) download
  1. #include <iostream>
  2.  
  3. namespace foo_detail {
  4. template <typename T>
  5. struct remap {
  6. // Default: Output type is the same as input type.
  7. typedef T type;
  8. };
  9.  
  10. template <>
  11. struct remap<char> {
  12. typedef unsigned char type;
  13. };
  14.  
  15. template <>
  16. struct remap<signed char> {
  17. typedef unsigned char type;
  18. };
  19.  
  20. template <typename T>
  21. void foo(int x);
  22.  
  23. template <>
  24. void foo<unsigned char>(int x) {
  25. std::cout << "foo<unsigned char>(" << x << ") called\n";
  26. }
  27. }
  28.  
  29. template <typename T>
  30. void foo(int x) {
  31. foo_detail::foo<typename foo_detail::remap<T>::type>(x);
  32. }
  33.  
  34. int main() {
  35. foo<char>(13);
  36. foo<signed char>(13);
  37. foo<unsigned char>(13);
  38. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
foo<unsigned char>(13) called
foo<unsigned char>(13) called
foo<unsigned char>(13) called