c++ - How to capture variable number of arguments in lambda function -
i tried following code doesn't compile.
template <class t, class... a> void tpool::enqueue(t&& func, a&&... args) { std::function<void()> task([func, args] () { //... }); }
just use ellipses. per paragraph 5.1.2/23 of c++11 standard:
a capture followed ellipsis pack expansion (14.5.3). [ example:
template<class... args> void f(args... args) { auto lm = [&, args...] { return g(args...); }; lm(); }
—end example ]
note: interestingly enough, gcc refusing compile (see live example):
template <class t, class... a> void foo(t&& func, a&&... args) { std::function<void()> task([func, args...] () { //... }); }
but considering above example standard, compiler issue.
Comments
Post a Comment