fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. void Test(T) {}
  6.  
  7. template<>
  8. void Test(int)
  9. {
  10. cout << "Int" << endl;
  11. }
  12.  
  13. template<>
  14. void Test(float)
  15. {
  16. cout << "Float" << endl;
  17. }
  18.  
  19. template<>
  20. void Test(char)
  21. {
  22. cout << "Char" << endl;
  23. }
  24.  
  25. template<>
  26. void Test(bool)
  27. {
  28. cout << "Bool" << endl;
  29. }
  30.  
  31. int main() {
  32. auto bool1 = true;
  33. auto int2 = 5;
  34. auto float1 = 10.f; // This is a float, but the default floating point type is a double
  35. auto byte1 = (char)'s';
  36. auto z1 = bool1 + int2; // z is a ? (assuming you've defined the + operator for boolean)
  37. auto z2 = float1 + int2; // z is a ?
  38. auto z3 = byte1 + int2; // z is a ?
  39. Test(bool1);
  40. Test(int2);
  41. Test(float1);
  42. Test(byte1);
  43. Test(z1);
  44. Test(z2);
  45. Test(z3);
  46. return 0;
  47. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Bool
Int
Float
Char
Int
Float
Int