Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2003-10-10 14:18:11

David Abrahams wrote:
> Eric Niebler wrote:
>> 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()
> That all sounds unconvincing to me. I believe the conversion should
> be more explicit if you want it:
> FOR_EACH(b, vector_of_bools)
> {
> whatever((int)b);
> }

Yes, but "it's impossible to achieve without typeof()". I think that's
pretty convincing. ;-) Besides, if you don't declare the type, how do
you know whether the loop variable should be a reference or a value?
Defaulting to a value or const reference is limitting; defaulting to a
non-const reference is dangerous.

I have an idea for how we could disallow an implicit conversion from
happening, if people think it's the Right Thing. But personally, I don't.

>>int i;
>>BOOST_FOREACH( i, int_list )
>>{ ... }
>>That way you can have access to the loop variable after the loop finishes.
> It's important to be able to do that; no doubt. It'd be nice to find
> a more-verbose syntax for that one, though ;^)

OK. I'm open to suggestions.

Eric Niebler
Boost Consulting

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