title: How do static variables in lambda function objects work?
body: <p>Are static variables used in a lambda retained across calls of the function wherein the lambda is used? Or is the function object "created" again each function call?</p>
  
  <p>Useless Example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using std::cout;
  
  void some_function()
  {
      std::vector&lt;int&gt; v = {0,1,2,3,4,5};
      std::for_each( v.begin(), v.end(),
           [](const int &amp;i)
           {
               static int calls_to_cout = 0;
               cout &lt;&lt; "cout has been called " &lt;&lt; calls_to_cout &lt;&lt; " times.\n"
                    &lt;&lt; "\tCurrent int: " &lt;&lt; i &lt;&lt; "\n";
               ++calls_to_cout;
           } );
  }
  
  int main()
  {
      some_function();
      some_function();
  }
  </code></pre>
  
  <p>What is the correct output for this program?
  Is it dependent on the fact if the lambda captures local variables or not? (it will certainly change the underlying implementation of the function object, so it might have an influence) Is it an allowed behavioural inconsistency?</p>
  
  <p>I'm not looking for: "My compiler outputs ...", this is too new a feature to trust current implementations IMHO. I know asking for Standard quotes seems to be popular since the world discovered such a thing exists, but still, I would like a decent source.</p>