Type substitution in template functions
We must carefully differentiate between the two steps in instantiating a template function to match a particular call - first, the types of the template parameters are deduced from the argument types (a process referred to as type deduction). Once the types are deduced, the concrete types are substituted for all parameter types (this is a process called type substitution). The difference becomes more obvious when the function has multiple parameters.
Type deduction and substitution
Type deduction and substitution are closely related, but not exactly the same. The deduction is the process of “guessing:” what should the template type, or types, be in order to match the call? Of course, the compiler does not really guess but applies a set of rules defined in the standard. Consider the following example:
// Example 07 template <typename T> void f(T i, T* p) { std::cout << “f(T, T*)” << std::endl...