SFINAE (Substitution Failure Is Not An Error) — if template argument substitution fails, the compiler removes that overload instead of erroring.
1#include <type_traits>23// Overload for integral types4template<typename T>5typename std::enable_if<std::is_integral<T>::value, T>::type6process(T value) {7 return value * 2;8}910// Overload for floating-point types11template<typename T>12typename std::enable_if<std::is_floating_point<T>::value, T>::type13process(T value) {14 return value + 0.5;15}1617process(42); // Calls integral overload18process(3.14); // Calls floating-point overload19// process("hi"); // Error — no matching overload
Modern alternative (C++20):