The title is rather hard to formulate in word, but here is what I\'m trying to achieve in non-compileable code:
template class Conta
Your only trouble here is that std::vector
is not a template
. It is a template
that happens to have a default argument for the second template parameter.
One way around this is using an alias template that really does take just one parameter:
#include
template class Container>
Container foo() {
return Container{1,2,3};
}
template
using Vec = std::vector;
int main() {
auto bar = foo();
return 0;
}
Another approach recommended in the comments is to use a variadic typename when declaring the template of the original function, which accepts any class template taking only type arguments. And then you can instantiate it with just one argument, since the actual template has a default for the second. This works in C++11 and above.
#include
template class Container>
Container foo() {
return Container{1,2,3};
}
int main() {
auto bar = foo();
return 0;
}