4

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.
    }
}
user2052436
  • 4,321
  • 1
  • 25
  • 46

0 Answers0