title: Can we get the type of a lambda argument?
body: <p>Using <code>std::function</code>, we can get the type of an argument using the <code>argument_type</code>, <code>second_argument_type</code> etc. typedefs, but I can't see a way to do the same thing with lambdas. Is it possible? (I'm using VS2010)</p>
  
  <p>Say I want something like the following in my deserialization system used to read an object and pass it to a setter function:</p>
  
  <pre><code>template&lt;typename F&gt; 
  static void forward(F f)
  { 
      // Create an object of the type of the first
      // parameter to the function object F
      typedef typename F::argument_type T;
      T t;
  
      //...do something with 't' here (deserialize in my case)
  
      // Forward the object to the function
      f(t);
  }
  </code></pre>
  
  <p>It can be used like this and everything works fine:</p>
  
  <pre><code>std::function&lt;void(int)&gt; f = [](int i) -&gt; void { setValue(i); };
  forward(f);
  </code></pre>
  
  <p>But it will not work directly with lambdas:</p>
  
  <pre><code>forward([](int i) -&gt; void { setValue(i); });
  //error C2039: 'argument_type' : is not a 
  //member of '`anonymous-namespace'::&lt;lambda1&gt;'
  </code></pre>
  
  <p>Is there a way to access the parameter types in a way that will work for both lambdas and <code>std::function</code> objects? Maybe a way to get the <code>std::function</code> type of a lambda first, and then the <code>argument_type</code> from that?</p>
  
  <hr>
  
  <p>Following on from the answer below, a version that works with lambdas and <code>std::function</code> is:</p>
  
  <pre><code>template&lt;typename T, typename F&gt; 
  static void forward(F f)
  { 
      T t;
  
      //...do something with 't' here (deserialize in my case)
  
      f(t);
  }
  
  forward&lt;int&gt;([](int i) -&gt; void { setValue(i); });
  </code></pre>
  
  <p>Since <code>int</code> is repeated here I was hoping to get rid of it - not so bad for <code>int</code> but more annoying for long-named types in a couple of namespaces. C'est la vie!</p>