title: How do I use variadic perfect forwarding into a lambda?
body: <p>I have a working function template that calls a lambda.</p>
  
  <p>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.</p>
  
  <p>I am using gcc 4.7.2.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Using R. Martinho Fernandes's suggestion, I looked up the error in bugzilla - <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41933">it does look like a bug that's been around for a while</a>.  If anyone knows of a workaround (I'm digging around for one now), please post an answer - ty.</p>
  
  <p><strong>ERRORS</strong></p>
  
  <pre><code>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&lt;std::basic_string&lt;char&gt;, typename T::Lambda&gt; MP(const string&amp;, M, Args&amp;&amp; ...) [with T = Integer; M = int (Integer::*)()const; Args = {}; typename T::Lambda = std::function&lt;std::function&lt;int()&gt;(const Integer&amp;)&gt;; std::string = std::basic_string&lt;char&gt;]’:
  junk.cpp:47:42:   required from here
  junk.cpp:34:2: error: using invalid field ‘MP(const string&amp;, M, Args&amp;&amp; ...)::&lt;lambda(const T&amp;)&gt;::__args’
  make: *** [junk] Error 1
  </code></pre>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;map&gt;
  
  struct Integer
  {
      typedef std::function&lt;int()&gt;                            Function;
      typedef std::function&lt;Function( Integer const&amp; inst )&gt;  Lambda;
  
      virtual int getInt() const = 0;
  };
  
  struct IntImpl : public Integer
  {
      virtual int getInt() const { return 42; }
  };
  
  typedef std::function&lt;int()&gt;                               IntFunction;
  typedef std::function&lt;IntFunction( Integer const&amp; inst )&gt;  IntLambda;
  
  #define WONT_COMPILE
  
  template&lt;typename T,typename M,typename... Args&gt;
  std::pair&lt;std::string,typename T::Lambda&gt;
  MP( std::string const&amp; str, M method, Args&amp;&amp;... args )
  {
  #ifdef WONT_COMPILE 
      return std::make_pair( str, 
          [=]( T const&amp; inst ) 
          {
              // COMPILE ERROR (Line 32) on next line
              return std::bind( method, std::cref( inst ), std::forward&lt;Args&gt;(args)...);
          } 
      );
  #else
      return std::make_pair( str, 
          [method]( T const&amp; inst ) 
          {
              return std::bind( method, std::cref( inst ));
          } 
      );
  #endif
  }
  
  std::map&lt;std::string,IntLambda&gt; const g_intTbl =
  {
      MP&lt;Integer&gt;( "getInt", &amp;Integer::getInt )
  };
  
  int
  main( int argv, char* argc[] )
  {
      IntImpl x;
      std::cerr &lt;&lt; g_intTbl.find("getInt")-&gt;second( x )() &lt;&lt; std::endl;
  }
  </code></pre>