Preferowane jest „if” z parametrami szablonu lub SFINAE?

Preferowane jest to:

template<typename T>
bool isNotZero(const T &a)
{
    if (std::is_floating_point<T>::value) return abs(a) > std::numeric_limits<T>::epsilon();
    else return a;
}

Albo to:?

template<typename T>
std::enable_if<std::is_floating_point<T>::value, bool>::type
isNotZero(const T &a) { return abs(a) > std::numeric_limits<T>::epsilon(); }

template<typename T>
std::enable_if<std::is_integral<T>::value, bool>::type
isNotZero(const T &a) { return a; }

Zazwyczaj używam pierwszego typu, aby uniknąć wielu wersji funkcji.

Wierzę, że to dokładnie to samo.

Pierwsza wersja zoptymalizowana na etapie opcode i druga wersja na etapie tworzenia szablonu.

questionAnswers(2)

yourAnswerToTheQuestion