Re: [boost] Re: FOREACH / C++ "for" proposal

In-Reply-To: <428133DD.20505@dcook.org> darren@dcook.org (Darren Cook) wrote (abridged):
Wouldn't someone wanting to do something "clever" like that fall back to using a normal for() or while() loop? I thought for(i:vect){} is a convenience function to save typing and make code clearer; can it do something a while() loop cannot?
I don't think it makes the code clearer, because it looks like a use of i rather than a declaration. I think it is very important for readability that names be declared explicitly. That is a general point. What you are proposing: for (i: vec) is especially misleading because it is inconsistent with: for (i = vec.begin(); i != vec.end(); ++i) I really don't think one should declare i and the other, not. What's wrong with: for (auto i: vec) ? -- Dave Harris, Nottingham, UK.

Dave Harris wrote:
What's wrong with:
for (auto i: vec)
?
Pretty much nothing unless auto is rejected, except the copy. for( auto i: v ) { i = 0; } for( auto& i: v ) is the typical foreach, unless v is vector<bool> or another proxied container.
participants (2)
-
brangdon@cix.compulink.co.uk
-
Peter Dimov