Explain SFINAE (Substitution Failure Is Not An Error).
Last updated
SFINAE (Substitution Failure Is Not An Error): if substituting template arguments into a candidate's signature yields an invalid type or expression, that overload is silently dropped instead of causing a compile error.
Only failures in the immediate context (return type, parameter types, template args) count. Errors inside the function body are hard errors.
Classically used with
std::enable_ifand type traits to enable overloads by type property. C++20conceptsandrequiresclauses are the clearer modern replacement.