----------------------------------------
> Date: Mon, 7 Jan 2008 01:41:05 -0800
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: Re: Introducing Cobra
> 
> for_each(foo.getBars().begin(), foo.getBars().end(), ....)
> 
> But a lot of C++ developers strongly resist that idiom, and sometimes
> the for loop is the cleanest way to represent the work being done.
> 
Th problem with for_each is the 3rd argument-  being forced to pass in a 
function pointer or functor.  Its just not clean.  If the inner loop needs to 
take local variables you haev a messy function call, possibly with in-outs.  
Even if it doesn't, you have the code physically broken up now in ways that 
might not be the best for readability.  If it was like the perl foreach, where 
it is a normal loop type and you put the body next just like a for loop, you'd 
see a lot less resistance to the idiom.

Personally I use foreach in perl and not in C++, just due to that.  I'd switch 
to using it in C++ in a second if that was fixed.  Any hope for that in the 0x 
standard (which isn't likely to come out in an 0x)

Gabe
_________________________________________________________________
Put your friends on the big screen with Windows Vista® + Windows Live™.
http://www.microsoft.com/windows/shop/specialoffers.mspx?ocid=TXT_TAGLM_CPC_MediaCtr_bigscreen_012008
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to