title: Can a functor retain values when passed to std::for_each?
body: <p>According to the first answer to <a href="https://stackoverflow.com/questions/317450/why-override-operator#317528">this</a> question, the functor below should be able to retain a value after being passed to <code>foreach</code> ( I couldn't get the <code>struct Accumulator</code> in the example to compile, so built a class).</p>
  
  <pre><code>class Accumulator
  {
      public:
          Accumulator(): counter(0){}
          int counter;
          void operator()(const Card &amp; c) { counter += i; }
  };
  </code></pre>
  
  <p>Example usage ( as per the example )</p>
  
  <pre><code>// Using a functor
  Accumulator acc;
  std::for_each(_cards.begin(), _cards.end(), acc);
  // according to the example - acc.counter contains the sum of all
  // elements of the deque 
  
  std::cout &lt;&lt; acc.counter &lt;&lt; std::endl;
  </code></pre>
  
  <p><code>_cards</code> is implemented as a <code>std::deque&lt;Card&gt;</code>. No matter how long <code>_cards</code> gets, <code>acc.counter</code> is zero after the <code>for_each</code> completes. As I step through in the debugger I can see counter incrementing, however, so is it something to do with <code>acc</code> being passed by value?</p>