Tho*_*mas 10 c++ templates g++ c++11
使用g ++执行此操作的正确方法是什么:
template < typename F >
void g (F f);
template < typename ... A >
void h (A ... a);
template < typename ... A >
void f (A ... a) {
g ([&a] () { h (a...); }); // g++-4.6: error: parameter packs not expanded with »...«
}
Run Code Online (Sandbox Code Playgroud)
SCF*_*nch 16
我认为你需要a在捕获列表中扩展包,如下所示:
template < typename ... A >
void f (A ... a) {
g ([&, a...] () { h (a...); });
}
Run Code Online (Sandbox Code Playgroud)
以下是C++ 0x最终委员会草案第5.1.2.23节中的相关文本:
捕获后跟省略号是包扩展(14.5.3).[例如:
Run Code Online (Sandbox Code Playgroud)template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); }- 结束例子]