4a46b0b4   
   From: dave@boostpro.com   
      
   on Thu Nov 03 2011, topoden wrote:   
      
   > On Nov 2, 2:19 pm, Dave Abrahams wrote:   
   >> Consider break, continue, goto, the ability to remember the   
   >> value of the last item seen, etc.   
   >>   
   >> On the other hand, for_each may perform library-based optimizations such   
   >> as loop unrolling and segmented traversal.   
   >>   
   >> They each have their own strengths. I'd say range-based for loops are   
   >> more flexible, while std::for_each is potentially more efficient.   
   >   
   > I understand "break, continue, goto" reasons. But can not we have "the   
   > ability to remember the value of the last item seen" with   
   > std::for_each + lambda + capture by ref? Say something like this:   
   >   
   > boost::optional prev_element;   
   > std::for_each(v.begin(), v.end(), [&prev_element] (int n)   
   > {   
   > ...   
   >   
   > prev_element = n;   
   > });   
      
   Yes, that works.   
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|