1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
#include <cstdio>
#include <type_traits>

template <typename T>
void
checkType(T)
{
    printf("Unknown type\n");
}

void
checkType(int)
{
    printf("int\n");
}

void
checkType(double)
{
    printf("double\n");
}

template <typename T, typename S>
typename std::common_type<T,S>::type
max(T a, S b)
{
    return (a>b) ? a : b;
}

int
main()
{
    checkType(max(1,   1.0));
    checkType(max(1.0, 1  ));
    checkType(max(1,   1  ));
    checkType(max(1.0, 1.0));
}