Consider the following two function templates
template<class T> void g(std::vector<T>&) {}
template<class T> void g(std::list<T>&) {}
together with the intermediate function
template<class Fct, class Container> void h(Fct&& f, Container& c)
{
f(c);
}
How do I call h
with an explicit instantiation of g
(like the first solution in this answer)? I tried these
std::vector<int> vec;
h(g<void(std::vector<int>&)>, vec); // Error, can't deduce template paramter Fct
h(g<void<int>(std::vector<int>&)>, vec); // Same problem
but now I'm lacking imagination for trying out an alternative syntax (I know that I can wrap the call in a lambda or a function object, but that's not what I want to do here). Thanks for suggestions!
Ok, I figured it out myself:
h<void(std::vector<int>&)>(g, vec);
It was confused about which function template to explicitly instantiate and incorrectly chose g
instead of h
.