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: 
Using c++11, std::enable\_if ( <http://en.cppreference.com/w/cpp/types/enable_if> ) can be used to do that:

```
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
void f(T t) {...}

```
Here is C++20 solution

```cpp
template<std::integral T>
void f(T v) {
   ...
}

```

I think It's actually overloaded function but works the same.