Just use ellipses. In clause 5.1.2 / 23 of the C ++ 11 standard:
A capture followed by an ellipsis is a packet extension (14.5.3). [Example:
template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); }
-end example]
Note. Interestingly, GCC refuses to compile this (see live example ):
template <class T, class... A> void foo(T&& func, A&&... args) { std::function<void()> task([func, args...] () { //... }); }
But, given the above example from the Standard, this is definitely a compiler problem.
source share