title: C++ Lambda stored in container capturing "this"
body: <p>Consider the following minimal code:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  class A
  {
  public:
    A() :
      s("dummy"),
      f([&amp;, this]{ return s == "dummy"; }),
    {}
    std::string s;
    std::function&lt;bool ()&gt; f;
  };
  
  int main(int argc, char *argv[])
  {
    A a;
    a.f(); // seems fine
  
    std::vector&lt;A&gt; as({});
    as[0].f(); // segmentation fault
  }
  </code></pre>
  
  <p>Class <code>A</code> has a lambda member that captures <code>this</code> pointer. When running the code above, lambda works fine when invoked from standalone <code>A</code> instance, but I get segmentation fault when called from an instance stored in the vector.</p>
  
  <p>Why does it happen?</p>