Question: Suppose I have a template function:

```
template<typename T>
void f(T t)
{
    ...
}

```

and I want to write a specialization for all primitive integer types. What is the best way to do this?

What I mean is:

```
template<typename I where is_integral<I>::value is true>
void f(I i)
{
    ...
}

```

and the compiler selects the second version for integer types, and the first version for everything else?

Answer: 
I would use overload resolution. That spares you from having to use the gross SFINAE hack. Unfortunately there are many areas where you can't avoid it, but this fortunately isn't one of those.

```
template<typename T>
void f(T t)
{
  f(t, std::is_integral<T>());
}

template<typename T>
void f(T t, std::true_type)
{ 
  // ...
}

template<typename T>
void f(T t, std::false_type)
{ 
  // ...
}

```
You can use a helper template that you can specialize like this:

```
#include <string>
#include <iostream>
#include <type_traits>

template <typename T, bool = std::is_integral<T>::value>
struct Foo {
        static void bar(const T& t) { std::cout << "generic: " << t << "\n"; }
};
template <typename T>
struct Foo<T, true> {
        static void bar(const T& t) { std::cout << "integral: " << t << "\n"; }
};

template <typename T>
static void bar(const T& t) {
        return Foo<T>::bar(t);
}

int main() {
        std::string s = "string";
        bar(s);
        int i = 42;
        bar(i);
        return 0;
}

```

output:

```
generic: string
integral: 42

```