为什么默认模板类型在实例化时不引用指定类型?

Why doesn't default template type refer to specified type in instantiation?

#include <typeinfo>
#include <iostream>
using namespace std;

template<typename T, typename U = T> void f1(T a, U b)
{
  cout<<typeid(a).name()<<endl;
  cout<<typeid(b).name()<<endl;
}

int main()
{
  f1<float>(1,2);
}

输出:

f

i ----> why is it int not default float as per template instantiation?

默认模板参数是最后的手段,仅在未指定或推导参数时使用。

[temp.deduct]/5中指定:

The resulting substituted and adjusted function type is used as the type of the function template for template argument deduction. If a template argument has not been deduced and its corresponding template parameter has a default argument, the template argument is determined by substituting the template arguments determined for preceding template parameters into the default argument. If the substitution results in an invalid type, as described above, type deduction fails. [ Example:

template <class T, class U = double>
void f(T t = 0, U u = 0);

void g() {
  f(1, 'c');        // f<int,char>(1,'c')
  f(1);             // f<int,double>(1,0)
  f();              // error: T cannot be deduced
  f<int>();         // f<int,double>(0,0)
  f<int,char>();    // f<int,char>(0,0)
}

— end example ]