[英]What's the correct syntax for passing an explicitly specified function template overload as a template parameter?
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 )? 如何使用
g
的显式实例化来调用h
(就像这个答案中的第一个解决方案)? 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). 但现在我缺乏尝试替代语法的想象力(我知道我可以将调用包装在lambda或函数对象中,但这不是我想要做的)。 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
. 关于哪个函数模板明确地实例化并错误地选择
g
而不是h
它很困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.