title: C++11 lambda capture `this` and capture local variables by value
body: <p>The lambda function below captures <code>this</code> (so <code>bar()</code> can access its instance vars) and the local variables <code>a,b,c</code>. </p>
  
  <pre><code>class Foo {
    int x, y, z;
    std::function&lt;void(void)&gt; _func;
    // ...
    void bar() {
       int a,b,c;
       // ...
       _func = [this,a,b,c]() { // lambda func
          int u = this-&gt;x + a;
          // ...
       };
    }
  };
  </code></pre>
  
  <p>But if I want to capture many instance variables and wish to avoid explicitly naming them in the capture list, I do <em>not</em> seem to be able to do this:</p>
  
  <pre><code>     _func = [this,=]() { // lambda func
          // ...
       };
  </code></pre>
  
  <p>I get a compiler error at the <code>=</code> following <code>this,</code>:</p>
  
  <pre><code>  error: expected variable name or 'this' in lambda capture list 
  </code></pre>
  
  <p>If I try this</p>
  
  <pre><code>     _func = [=,this]() { // lambda func
          // ...
       };
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>  error: 'this' cannot be explicitly captured when the capture default is '='
  </code></pre>
  
  <p>Is there a shorthand for capturing <code>this</code> and everything else by value?</p>
  
  <p><strong>UPDATE:</strong> <code>[=, this]</code> as a lambda capture is a <a href="https://en.cppreference.com/w/cpp/20" rel="nofollow noreferrer">new feature of C++20</a></p>