Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++SFINAE and enable_ifSingle-choice MCQ

Why does putting `std::enable_if` only in the template parameter list (not the return type) let you overload two function templates with otherwise identical signatures, while a common mistake breaks it?

// Mistake that fails to compile as an overload pair: template <class T, class = std::enable_if_t<std::is_integral_v<T>>> void f(T); template <class T, class = std::enable_if_t<std::is_floating_point_v<T>>> void f(T);