title: STL for_each with multiple return values and/or virtual base class functor
body: <p>I trying to convert some loops in my code to use the for_each functionality of the STL.  Currently, I calculate and accumulate two separate values over the same set of data, requiring me to loop over the data twice.  In the interest of speed, I want to loop once and accumulate both values.  Using for_each was suggested as it apparently can be worked into a multithreaded or multiprocessor implementation fairly easily (I haven't learned how to do that yet.)</p>
  
  <p>Creating a function that only loops over the data once and calculates both values is easy, but I need to return both.  To use with for_each, I need to return both calculated values at each iteration so STL can sum them.  From my understanding, this isn't possible as for_each expects a single value returned.</p>
  
  <p>The goal with using for_each, besides cleaner code (arguably?) is to eventually move to a multithreaded or multiprocessor implementation so that the loop over the data can be done in parallel so things run faster.</p>
  
  <p>It was suggested to me that I look at using a functor instead of a function.  However, that raises two issues.  </p>
  
  <ol>
  <li>How will using a functor instead allow the return accumulation of two values?</li>
  <li>I have two methods of applying this algorithm.  The current code has a virtual base class and then two classes that inherit and implement the actual working code.  I can't figure out how to have a "virtual functor" so that each method class can implement its own version.</li>
  </ol>
  
  <p>Thanks!</p>