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
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
#include <cstdio>
#include <type_traits>

// nobody is foo
template <typename T>
struct IsFoo
{
    static const bool value = false;
};

// ... except for `double`
template <>
struct IsFoo<double>
{
    static const bool value = true;
};

// ... and `int`
template <>
struct IsFoo<int>
{
    static const bool value = true;
};

//----------------------------------------------------

template <typename T>
typename std::enable_if<IsFoo<T>::value, void>::type
print(const T &)
{
    std::printf("Is foo\n");
}

template <typename T>
typename std::enable_if<! IsFoo<T>::value, void>::type
print(const T &)
{
    std::printf("Is not foo\n");
}

int
main()
{
    print(false);
    print('c');
    print(42);
    print(1.2f);
    print(1.2);
}