title: Return type of a C++ lambda
body: <p>I'm writing a template function that takes a function object (for now, a lambda) as a parameter, with lambda datatype as a template parameter, and returns the same type the lambda returns. Like this:</p>
  
  <pre><code>template&lt;typename TFunctor, typename TReturn&gt;
  TReturn MyFunc(TFunctor &amp;Func, TReturn) //The second arg is just to keep the template spec happy
  {
      return Func();
  }
  </code></pre>
  
  <p>And the consumption code goes like this:</p>
  
  <pre><code>int n = MyFunc([](){return 17;}, int());
  </code></pre>
  
  <p>I don't like the ugly way the return datatype is specified. Is there some built-in typedef in the compiler-generated lambda class that would give me its return type? So that MyFunc can go somehow like this:</p>
  
  <pre><code>template&lt;typename TFunctor&gt;
  TFunctor::return_type MyFunc(TFunctor &amp;Func)
  { //...
  </code></pre>
  
  <p>I want it to return the same type that lambda returns without explicitly spelling out that type.</p>
  
  <p>EDIT: for now, all lambdas I'm concerned with are argumentless. Variable capture does the trick just as well.</p>