I was trying to simplify a template function by using a template alias instead of the underlying type:
template<typename T,
typename Traits = std::char_traits<T>,
typename Allocator = std::allocator<T>,
typename String = std::basic_string<T, Traits, Allocator>,
typename Vector = std::vector<String>>
Vector make_vector_from_string(const String & str)
{
//do something with str parameter
return Vector{
{str}
};
}
But the caller is required to specify the template type because the compiler fails to deduce T for the parameter:
std::string bar{"bar"};
auto strings{make_vector_from_string<char>(bar)};
If the function parameter type is changed to std::basic_string<T, Traits, Allocator>
instead of String
the caller can simply call make_vector_from_string(bar);
without having to specify the template parameter. Why is that?