title: Capturing pointers in lambda expression?
body: <p>I have a function that uses a lambda expression.</p>
  
  <pre><code>std::vector&lt;Bar*&gt; mBars;
  
  void foo(Bar* bar)
  {
      auto duplicateBars = std::remove_if(mBars.begin(), mBars.end(),
          [bar] (const Bar* const &amp;element)
          {
              return bar == element;
          });
  
      mBars.erase(duplicateBars, mBars.end());
  }
  </code></pre>
  
  <p>Later, I reviewed the code and realized I could add two consts to foo's signature.</p>
  
  <pre><code>void foo(const Bar* const bar);
  </code></pre>
  
  <p><code>bar</code>'s pointer and data is now constant, but for the purpose of the lambda expression the pointer itself is constant, because I captured by value.  However, the data pointed to can be changed and there is no way to change this, because <code>const</code> is not allowed in the lambda capture.</p>
  
  <p>This is unintuitive to me.  Is my interpretation correct?  I can use the second signature, but I cannot protect the data from being changed in the lambda expression.</p>