
BOOST_FOREACH is a macro which makes it simple to iterate over a sequence. It is concise, and clearly expresses the programmer's intentions. For example: short array_short[] = {1,2,3}; BOOST_FOREACH( short & i, array_short ) { ++i; } // array_short contains {2,3,4} here Recent changes I have made to the macro have greatly increased its safety and usefulness. It gracefully handles both L-value and R-value sequence expression, and evaluates its arguments only once. It now works (to a greater or lesser extent) on a wide range of compilers, even VC6. The current implementation, documentation and tests can be found in the Boost Sandbox File Vault. You can download the Zip file here: http://tinyurl.com/57oyp Tinyurl link redirects to: http://boost-sandbox.sourceforge.net/vault/index.php?action=downloadfile&filename=foreach.zip&directory=eric_niebler& -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler <eric@boost-consulting.com> wrote:
BOOST_FOREACH is a macro which makes it simple to iterate over a... <snip>
Just wanted to say thanks. I grepped my current project and, even though I'm macro averse, I noticed that I use BOOST_FOREACH a lot now. Your current version plugged right in with no problems. It makes code like: // normalise BOOST_FOREACH( double & w, weight_ ) { w /= min_w; } much easier and clearer. Thanks, Matt.

"Eric Niebler" wrote:
Tinyurl link redirects to: http://boost-sandbox.sourceforge.net/vault/index.php?action=downloadfile&filename=foreach.zip&directory=eric_niebler&
The links don't work (in IE 6), but one can get there manually from http://boost-sandbox.sourceforge.net/ *Very* useful library, thanks, /Pavel

Pavel Vozenilek wrote:
"Eric Niebler" wrote:
Tinyurl link redirects to: http://boost-sandbox.sourceforge.net/vault/index.php?action=downloadfile&filename=foreach.zip&directory=eric_niebler&
The links don't work (in IE 6), but one can get there manually from http://boost-sandbox.sourceforge.net/
You could also try the direct link to the file: http://boost-sandbox.sourceforge.net/vault/files/eric_niebler/foreach.zip I'll see if I can make that link info show up in the file lists. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq

On Sat, 18 Dec 2004 21:05:24 -0800, Eric Niebler wrote
BOOST_FOREACH is a macro which makes it simple to iterate over a sequence. It is concise, and clearly expresses the programmer's intentions. ...snip...
I've put you in the review queue...which seems to be stalled out at the moment. http://www.boost.org/more/formal_review_schedule.html Jeff

"Eric Niebler" <eric@boost-consulting.com> wrote in message news:41C50C14.3040408@boost-consulting.com... | | BOOST_FOREACH is a macro which makes it simple to iterate over a | sequence. It is concise, and clearly expresses the programmer's | intentions. For example: | | short array_short[] = {1,2,3}; | BOOST_FOREACH( short & i, array_short ) | { | ++i; | } | // array_short contains {2,3,4} here looks great Eric. what about a BOOST_REVERSE_FOREACH ? br Thorsten

Thorsten Ottosen wrote:
what about a BOOST_REVERSE_FOREACH ?
Hey, the formal review hasn't started yet! :-) Actually, I don't think BOOST_REVERSE_FOREACH is the right way to approach this. I'd rather see this done with range adaptors: BOOST_FOREACH( int i, adaptor::reverse(vect) ) { } ... where adaptor::reverse() returns an iterator_range<> (from Boost.Range) of reverse_iterator<> (from Boost.Iterator). I'm working on a set of range adaptors, which I hope to add to boost-sandbox after Christmas. This would be a separate library from BOOST_FOREACH, but it would work well with it. -- Eric Niebler Boost Consulting www.boost-consulting.com -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.296 / Virus Database: 265.6.0 - Release Date: 12/17/2004

Eric Niebler <eric <at> boost-consulting.com> writes:
Thorsten Ottosen wrote:
what about a BOOST_REVERSE_FOREACH ?
Hey, the formal review hasn't started yet! Actually, I don't think BOOST_REVERSE_FOREACH is the right way to approach this. I'd rather see this done with range adaptors:
BOOST_FOREACH( int i, adaptor::reverse(vect) ) { }
... where adaptor::reverse() returns an iterator_range<> (from Boost.Range) of reverse_iterator<> (from Boost.Iterator).
yeah, right, seems better.
I'm working on a set of range adaptors, which I hope to add to boost-sandbox after Christmas. This would be a separate library from BOOST_FOREACH, but it would work well with it.
ok, be sure to check with John Torjo to see if you don't overlap too much in functionality with his range adaptors. If there is filter_iterator, then he has a filter_range and a filtered() function etc. -Thorsten
participants (7)
-
Eric Niebler
-
Jeff Garland
-
Matt Hurd
-
Pavel Vozenilek
-
Rene Rivera
-
Thorsten Ottosen
-
Thorsten Ottosen