Boost logo

Boost :

Subject: Re: [boost] [Foreach] Proposal to simplify using Boost.Foreach with maps
From: Chris Purcell (chris.purcell.39_at_[hidden])
Date: 2009-09-14 15:04:06


2009/9/14 Markus Werle <numerical.simulation_at_[hidden]>:
> Chris Purcell <chris.purcell.39 <at> gmail.com> writes:
>>     std::map<int, int> my_map;
>>     BOOST_FOREACH_PAIR(int key, int value, my_map)
>>       std::cout << key << " : " << value << "\n";
>
> Can you provide a link to the code?
> I'd like to test it.

I haven't got a web page to put it, but it's pretty small, so I've put
it inline sans newlines. It's alpha-quality only.

#define BOOST_FOREACH_PAIR(KEY, VALUE, COL) BOOST_FOREACH_PREAMBLE()
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col)
= BOOST_FOREACH_CONTAIN(COL)) {} else if
(boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) =
BOOST_FOREACH_BEGIN(COL)) {} else if
(boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) =
BOOST_FOREACH_END(COL)) {} else for (bool
BOOST_FOREACH_ID(_foreach_continue) = true,
BOOST_FOREACH_ID(_foreach_key_loop) = true;
BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL);
BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) :
(void)0) if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue)))
{} else if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_key_loop)))
{} else for (KEY = BOOST_FOREACH_DEREF(COL).first;
!BOOST_FOREACH_ID(_foreach_key_loop);
BOOST_FOREACH_ID(_foreach_key_loop) = true) for (VALUE =
BOOST_FOREACH_DEREF(COL).second; !BOOST_FOREACH_ID(_foreach_continue);
BOOST_FOREACH_ID(_foreach_continue) = true)

I don't know if there are any changes to the library on subversion
trunk; the above works with Boost 1.40.0. Any line breaks have been
added en-route.

Cheers,
Chris


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