home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,599 of 33,346   
   Dave Abrahams to All   
   Re: "for_each + lambda" vs "ranged for"   
   02 Nov 11 11:19:13   
   
   From: dave@boostpro.com   
      
   on Tue Nov 01 2011, Carlo Milanesi    
   wrote:   
      
   > On 01/11/2011 11.58, topoden wrote:   
   >> Given we now have ranged for loops... Why do we still need   
   >> std::for_each + lambda? Doesn't ranged for loop do exactly the same   
   >> now?   
   >   
   > I would say: "Given we now have lambdas ... Why do we still need   
   > ranged-for loops?"   
   >   
   > Lambda is much more powerful than ranged-for.   
      
   Not really.  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.   
      
   --   
   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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca