From: Dave Harris (brangdon_at_[hidden])
Date: 2005-05-02 12:57:34
eric_at_[hidden] (Eric Niebler) wrote (abridged):
> It injects 5 local variables. I haven't checked, but I suspect that
> some can be optimized away sometimes.
I doubt they will be in debug mode, which is when I need to look at them.
> I'm not sure why users will need to understand how FOREACH uses
> its hidden variables. Can you explain?
When I am debugging, I need to understand what the code is doing else how
I can I understand what it is doing wrong?
For example, from looking at the implementation it seems that the macro
caches the end() value in a variable called _foreach_end. This means that
if some random memory corruption changes that variable the loop may never
terminate. I need to know.
Incidently, if it is caching then code like:
BOOST_FOREACH( int i, vec )
vec.push_back( filter(i) );
will not work the same as:
for (iterator i = vec.begin(); i != vec.end(); ++i)
vec.push_back( filter(*i) );
Which at least needs to be documented. Again the implementation is complex
enough that I can't tell at a glance whether these are the same, so I may
have this wrong, but I strongly suspect they are different.
-- Dave Harris, Nottingham, UK.