使用自由函数作为伪构造函数以避免显式指定模板参数是一种常见的模式/习惯用法吗?
例如,每个人都知道std::make_pair,它使用它的参数来推断pair类型:
template <class A, class B>
std::pair<A, B> make_pair(A a, B b)
{
return std::pair<A, B>(a, b);
}
// This allows you to call make_pair(1, 2),
// instead of having to type pair<int, int>(1, 2)