Item 59. SFINAE
In attempting to use function template argument deduction to select among a number of overloaded function templates and nontemplate functions, the compiler may attempt a specialization that fails on one or more of them.
template <typename T> void f( T );template <typename T> void f( T * );//...f( 1024 ); // instantiates first f
Even though substitution of the nonzero integer for T * in the second f function template would have been incorrect, the attempted substitution does not give rise to an error provided that a correct substitution is found. In this case, the first f is instantiated, and there is no error. Thus, we have the “substitution failure is not an error” concept, dubbed SFINAE by Vandevoorde and Josuttis.
SFINAE ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access