I want to have a templated function in C++, where one template parameter is itself a template of another template parameter. If that doesn\'t make any sense, take the follow
std::vector
has two parameters, type and allocator.
Try this
template class V>
void print_container(V &con)
{
}
print_container(vec);
This will work for vector
, list
, etc., but will not work with map
, set
.
However, since you use auto
you can use C++11 and then you can to this:
template class V, typename... Args>
void print_container(V &con)
or
template class V, typename... Args>
void print_container(V &con)
and of course most simple way is to do something like
template
void print_container(C& con)
probably with some checks for deduce, that C
is really container.
template
auto print_container(C& con) -> decltype(con.begin(), void())