Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2003-10-10 13:12:30

Russell Hind wrote:
> One thing that worries me about the inital example is if you forget to
> declare i as a reference, then it breaks.

No, it doesn't. Your iteration variable can be a reference or a value,
whichever you want.

> Could the type of the local not be auto-declared?

That's not a good idea -- putting the type there is more explicit, and
it makes it look more like a for(;;) loop. Besides, you might want a
conversion to occur; for example, BOOST_FOREACH( int i, vector_of_bools
). Also it's impossible to achieve without typeof() AFAICT.

> BOOST_FOREACH(i, int_list)

This syntax is reserved for when you have predeclared the loop variable,
as in:

int i;
BOOST_FOREACH( i, int_list )
{ ... }

That way you can have access to the loop variable after the loop finishes.

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at