Suppose I have a template function:
template
void f(T t)
{
...
}
and I want to write a specialization for all primiti
Use SFINAE
// For all types except integral types:
template
typename std::enable_if::value>::type f(T t)
{
// ...
}
// For integral types only:
template
typename std::enable_if::value>::type f(T t)
{
// ...
}
Note that you will have to include the full std::enable_if return value even for the declaration.
C++17 update:
// For all types except integral types:
template
std::enable_if_t> f(T t)
{
// ...
}
// For integral types only:
template
std::enable_if_t> f(T t)
{
// ...
}