title: C++11 - lambda function pass vector in capture and modify it
body: <p>I have this code:</p>
  
  <pre><code>#include &lt;iostream&gt; 
  #include &lt;functional&gt;
  #include &lt;vector&gt;
  
  int main () {
    std::vector&lt;int&gt; kk;
    kk.push_back(2);
    std::function&lt;int(int)&gt; foo = std::function&lt;int(int)&gt;([kk](int x)
    {
        kk.push_back(1);
        return kk[0]+1;
    });
  
    std::cout &lt;&lt; "foo: " &lt;&lt; foo(100) &lt;&lt; '\n';
  
    return 0;
  }
  </code></pre>
  
  <p>Why I cannot modify vector <code>kk</code>, passed via capture, inside lambda function?</p>
  
  <p>I got this error:</p>
  
  <blockquote>
    <p>11:21: error: passing 'const std::vector' as 'this' argument of
    'void std::vector&lt;_Tp, _Alloc>::push_back(std::vector&lt;_Tp,
    _Alloc>::value_type&amp;&amp;) [with _Tp = int; _Alloc = std::allocator; std::vector&lt;_Tp, _Alloc>::value_type = int]' discards qualifiers
    [-fpermissive]</p>
  </blockquote>
  
  <p>I can pass it by reference, but problem is, that it will go out of scope if my lambda is called from thread and vector will no longer be available.</p>