Boost logo

Boost :

From: Sam Saariste (ss_march2001_at_[hidden])
Date: 2005-04-28 13:43:21


> > I have used it for more than 6 months now and have added it to my
standard
> > set of idioms. Once you get into the FOREACH mindset, you don't only
want to
> > use it for std::for_each type jobs but you would also want to use it for
> > std::transform type ones. In situations where you can use push_back on a
> > result container, FOREACH serves this purpose as it is. However, I have
> > encountered situations where this was not possible and where I wanted a
> > second macro, say FOREACH2, that iterates over 2 ranges simultaneously.
I
> > have had such a need on more than one occasion. One situation was as
above
> > and in other situations I had to combine the elements of two ranges.
>
> Try using zip_iterator with BOOST_FOREACH.
>
Thanks for the suggestion Dave, but I am not sure how I would achieve the
same as with the BOOST_FOREACH variant that I am suggesting. I am thinking
of something like the following:

int a1[] = { 1, 2, 3 };
int a2[] = { 4, 5, 6 };
BOOST_FOREACH2(int e1, a1, int& e2, a2)
{
    e2 += e1;
}

How would I write this with BOOST_FOREACH using zip_iterator?

TIA,
Sam


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