I've seen a few questions here relating to a gcc bug with capturing variadic arguments in a lambda. See for example: Does lambda capture support variadic template arguments or Compiler bug, or non standard code? - Variadic template capture in lambda. I have the following contrived example of what I'm trying to do
#include <iostream>
#include <functional>
class TestVariadicLambda {
public:
template<typename... Args>
std::function<void()> getFunc(Args... args) {
return [=]{ printArgs(args...); };
}
template<typename T, typename... Args>
void printArgs(T value, Args... args) {
std::cout << value << ", ";
printArgs(args...);
}
void printArgs() {std::cout << "\n";}
};
In gcc 4.8.2 I get the following errors:
../src/TestVariadicLambda.h: In lambda function:
../src/TestVariadicLambda.h:9:25: error: parameter packs not expanded with ‘...’:
return [=]{ printArgs(args...); };
^
../src/TestVariadicLambda.h:9:25: note: ‘args’
../src/TestVariadicLambda.h:9:29: error: expansion pattern ‘args’ contains no argument packs
return [=]{ printArgs(args...); };
^
My question is how do I work around this since it won't work in gcc4.8