title: C++ Lambdas: capture list vs. parameter list
body: <p>According to the C++11 standard, lambda expressions may use variables in the enclosing scope, by means of the capture list, the parameter list or both. </p>
  
  <p>So, let's look to two versions of the same code.</p>
  
  <p>1) With capture</p>
  
  <pre><code>int x = 4;
  
  cout &lt;&lt; "With capture  : Factorial of " &lt;&lt; x &lt;&lt; " = " &lt;&lt; [x]() // &lt;= Capture
  {
      int r = 1;
      for (int i = x; i &gt; 1; i--) r = r * i;
      return r;
  }() &lt;&lt; endl;
  </code></pre>
  
  <p>2) With parameter</p>
  
  <pre><code>int x = 4;
  
  cout &lt;&lt; "With parameter: Factorial of " &lt;&lt; x &lt;&lt; " = " &lt;&lt; [](int x) // &lt;= Parameter
  {
      int r = 1;
      for (int i = x; i &gt; 1; i--) r = r * i;
      return r;
  }(x) &lt;&lt; endl;
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>With capture  : Factorial of 4 = 24
  With parameter: Factorial of 4 = 24
  </code></pre>
  
  <p>Since we can pass parameters to lambdas in the parameter list (just as with any C++ function), why do we need the capture list?</p>
  
  <p>Can someone show me cases where parameter list doesn't work and only capture list does?</p>