title: Lambda syntax with algorithms
body: <p>I read <a href="http://en.cppreference.com/w/cpp/language/lambda" rel="nofollow noreferrer">here</a> and also <a href="https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11">here</a> and examples on cpluplus.com
  And I still don't understand how it works</p>
  
  <p>what confuses me at most how lambdas work with _if algorithms like copy_if that they don't reference containers in the body</p>
  
  <pre><code>     std::vector&lt;int&gt; foo = {25,15,5,-5,-15};
           std::vector&lt;int&gt; bar (foo.size());
  
            // copy only positive numbers:
            auto it = std::copy_if (foo.begin(), foo.end(), bar.begin(), [](int i)
          {return !(i&lt;0);} )
  </code></pre>
  
  <p>doesn't reference vector object foo in the body. so how it performs the desired action?</p>
  
  <p>Additionally, I don't understand what is the difference beetween capturing a variable and passing as parameter</p>
  
  <p>I also tried my own example:</p>
  
  <pre><code>vector&lt;unsigned long&gt;v2(10);
  for(unsigned long i=0;i&lt;v2.size();i++)
      v2[i]=10-i;
  v2.erase(remove_if(v1.begin(), v1.end(),[](unsigned long n) { 
  
      return n%2==1; } ),v2.end());//remove odd numbers
  </code></pre>
  
  <p>It compiles (MVS 2010 with Intel Composer 14) but produces rubbish and assertion error.</p>