Function template specialization vs if-constexpr

Viewed 174

Is there a conceptual (or other) difference between specializing function template and using if constexpr?

E.g.:

template<class T>
void fun(T t)
{
    // Generic code.
}

template<>
void fun(int t)
{
    // int code.
}

Vs.

template<class T>
void fun(T t)
{
    if constexpr(std::is_same_v<T, int>) 
    {
        // int code.
    } 
    else 
    {
        // Generic code.
    }
}
0 Answers
Related