title: C++ type of lambda closure returned from functions
body: <p>Consider the following example code:</p>
  
  <pre><code>int main()
  {
      auto id = []()
      {
          auto ret = [](auto u) { return u; };
          return ret;
      };
  
      //same closure type -- prints '1'
      auto f1 = id();
      auto g1 = id();
      std::cout&lt;&lt;std::is_same&lt;decltype(f1), decltype(g1)&gt;::value&lt;&lt;std::endl;
  
      //differenct closure type -- prints '0'
      auto f2 = [](auto u) { return u; };
      auto g2 = [](auto u) { return u; };    
      std::cout&lt;&lt;std::is_same&lt;decltype(f2), decltype(g2)&gt;::value&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p><a href="http://coliru.stacked-crooked.com/a/6dc7a23c7c8bb677" rel="nofollow noreferrer">DEMO</a></p>
  
  <p>Questions:</p>
  
  <ul>
  <li>Why is the type of the returned closure object identical in the first call of <code>std:is_same</code>? (The same result is obtained using a "normal" function template, and also when <code>add</code> is defined in the body of <code>main()</code>.)</li>
  <li>What is the difference to the second call where -- as I expected from <a href="https://stackoverflow.com/a/18756007/2412846">this answer</a> -- the closure types are different?</li>
  </ul>