title: Cost of capture by reference/value in lambda function?
body: <p>Consider the following code :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;numeric&gt;
  
  int main()
  {
      const unsigned int size = 1000;
      std::vector&lt;int&gt; v(size);
      unsigned int cst = size/2;
      std::iota(v.begin(), v.end(), 0);
      std::random_shuffle(v.begin(), v.end());
      std::cout&lt;&lt;std::find_if(v.begin(), v.end(), [&amp;cst](const int&amp; i){return i == cst;})-v.begin()&lt;&lt;std::endl;
      std::cout&lt;&lt;std::find_if(v.begin(), v.end(), [=](const int&amp; i){return i == cst;})-v.begin()&lt;&lt;std::endl;
      return 0;
  }
  </code></pre>
  
  <p>This code fills a vector with values, shuffles it and then searches the index of a specified value (it is just an example to illustrate my problem). This value <code>cst</code> can be captured by reference or by value in the lambda function. </p>
  
  <p>My question: is there a difference in performance between the two versions or will they be optimized in the same way by the compiler? </p>
  
  <p>Is is a good rule to pass constant fundamental types by value and constant classes by reference (like in normal functions) ?</p>