18
I have a working function template that calls a lambda.
I would like to generalize this function template to take variadic arguments and forward them perfectly into the lambda, but I am having trouble getting this code to compile.
I am using gcc 4.7.2.
UPDATE
Using R. Martinho Fernandes's suggestion, I looked up the error in bugzilla - it does look like a bug that's been around for a while. If anyone knows of a workaround (I'm digging around for one now), please post an answer - ty.
ERRORS
junk.cpp: In lambda function:
junk.cpp:32:68: error: parameter packs not expanded with ‘...’:
junk.cpp:32:68: note: ‘args’
junk.cpp: In instantiation of ‘std::pair<std::basic_string<char>, typename T::Lambda> MP(const string&, M, Args&& ...) [with T = Integer; M = int (Integer::*)()const; Args = {}; typename T::Lambda = std::function<std::function<int()>(const Integer&)>; std::string = std::basic_string<char>]’:
junk.cpp:47:42: required from here
junk.cpp:34:2: error: using invalid field ‘MP(const string&, M, Args&& ...)::<lambda(const T&)>::__args’
make: *** [junk] Error 1
CODE
#include <functional>
#include <iostream>
#include <map>
struct Integer
{
typedef std::function<int()> Function;
typedef std::function<Function( Integer const& inst )> Lambda;
virtual int getInt() const = 0;
};
struct IntImpl : public Integer
{
virtual int getInt() const { return 42; }
};
typedef std::function<int()> IntFunction;
typedef std::function<IntFunction( Integer const& inst )> IntLambda;
#define WONT_COMPILE
template<typename T,typename M,typename... Args>
std::pair<std::string