Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-03-10 13:00:31


Russell Hind wrote:
> Is there a way to reverse iterator using BOOST_FOREACH? From a quick
> browse of the docs, it isn't mentioned. I guess it could be done using
> a std::pair of reverse iterators, but would it be easy to build a
> BOOST_REVERSE_FOREACH construct or BOOST_RFOREACH that just runs from
> rbegin to rend?
>

Grab the range algorithms and adaptors library from the file vault. You
can find it in the file range_ex.zip at:

http://tinyurl.com/5qhj8
http://boost-sandbox.sourceforge.net/vault/index.php?directory=eric_niebler

There you'll find the "reverse" range adaptor, which you can use with
BOOST_FOREACH like this:

using boost::adaptor::reverse;
BOOST_FOREACH( int i, my_list | reverse )
{
     // ...
}

It's anybody's guess how Borland will handle this, though. :-P

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk