I'd like to replicate the following with BOOST FOREACH
std::vector<int>::const_iterator i1;
std::vector<int>::const_iterator i2;
for( i1 = v1.begin(), i2 = v2.begin();
i1 < v1.end() && i2 < v2.end();
++i1, ++i2 )
{
doSomething( *i1, *i2 );
}
Iterating over two things simultaneously is called a "zip" (from functional programming), and Boost has a zip iterator:
Note that it's an iterator, not a range, so to use
BOOST_FOREACHyou're going to have to stuff two of them into an iterator_range orpair. So it won't be pretty, but with a bit of care you can probably come up with a simplezip_rangeand write:Or special-case for 2 and use
std::pairrather thanboost::tuple.I suppose that since
doSomethingmight have parameters(int&, int&), actually we want atuple<int&,int&>. Hope it works.