[foreach] and reverse iteration

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? Cheers Russell

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
participants (2)
-
Eric Niebler
-
Russell Hind