Re: [boost] Re: Formal Review: FOREACH macro

In-Reply-To: <4277C3E9.60407@boost-consulting.com> eric@boost-consulting.com (Eric Niebler) wrote (abridged):
Is do/while an algorithm?
for (iterator i = c.begin(); i != c.end(); ++i) is an algorithm. Do/while would be if it included the code to step through a container.
You probably don't think of it that way. It's certainly not an algorithm in the STL sense like std::for_each is.
Again, a for-loop is.
The most effective way to think of BOOST_FOREACH (in my experience) is as a new looping construct -- a foreach keyword.
It's not a keyword. It's a macro which encapsulates an algorithm - roughly the same algorithm as std::for_each.
To encourage people to think of it as an algorithm in the STL sense would be a mistake. It is range-based, not iterator-based.
An algorithm does not need to be iterator-based to be an algorithm.
You can break and continue and return from the loop body. You can't do any of those things from an STL algorithm.
That's because the STL algorithms encapsulate differently, not because they are not algorithms. In any case, the question of whether FOREACH is an algorithm is a red herring, because the use of underlines as word separators does not just apply to algorithms. It also applies to macros (eg "BOOST_STATIC_ASSERT") and keywords (eg "static_cast"). Although there are some C++ keywords that don't have underlines, eg "sizeof", these are mostly inherited from C. The modern trend is for underlines unless there is a compelling reason otherwise. You've not offered a compelling reason. It sounds like you are mimicking the "foreach" of some other language. I think a C++ library should use C++ conventions, not the conventions of whatever it is you are copying. Consistency is important. Also, program text is easier to read if words don't all run together. -- Dave Harris, Nottingham, UK.

Dave Harris wrote:
It sounds like you are mimicking the "foreach" of some other language. I think a C++ library should use C++ conventions, not the conventions of whatever it is you are copying.
The C++ 'foreach' is likely to be spelled 'for', if I'm not mistaken. for( int v: c ) { } http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1650.html#85 unless something has changed in the meantime.

Peter Dimov wrote:
Dave Harris wrote:
It sounds like you are mimicking the "foreach" of some other language. I think a C++ library should use C++ conventions, not the conventions of whatever it is you are copying.
The C++ 'foreach' is likely to be spelled 'for', if I'm not mistaken.
for( int v: c ) { }
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1650.html#85
Well, in that case, I suggest that BOOST_FOREACH be spelled: BOOST_FOR Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (3)
-
brangdon@cix.compulink.co.uk
-
Joel
-
Peter Dimov