I have this situation:
#include
template
U f(T data) {
return U();
}
int main() {
std::vector
The issue here is std::vector doesn't have just one template parameter. It also has a parameter for the allocator type. To get around that you can add another template parameter, or just use a variadic template template parameter like
template class T, class U>
U f(T data) {
return U();
}
which will work with
return f(vec);
or even better
return f(vec);
Do note that this behavior has been changed in C++17. With DR: Matching of template template-arguments excludes compatible templates they relaxed the rules and
template class T, class U>
U f(T data) {
return U();
}
will work with gcc in C++17 mode and clang in C++17 with -frelaxed-template-template-args enabled.