On Thu, Jul 22, 2010 at 11:12 PM, Justin Leonard <justinleona@gmail.com> wrote:
I think I'm missing something obvious - but here goes.
I'm trying to rewrite the a loop similar to the following using boost::range:

[code]
boost::range_iterator<Doubles>::type i = boost::begin(first_range);
boost::range_iterator<Doubles>::type j = boost::begin(second_range);

for( ; i != boost::end(first_range) && j != boost::end(second_range); ++i,++j) {
   if( f(*i) )
      g(*j);
}
[/code]

Is there something similar to:
[code]
for_each( filtered( second_range,first_range,f ) , g );
[/code]
to use in place of the above?


Well, depending on how much you want to use a range based approach, you
could construct zip iterators of your two ranges, then put your begin/end into a
pair, and use that as your range. The application of f() and g() would need to be
wrapped in binds, to pick out the doubles from the tuple resulting from dereferencing
the zip iterator.

If you do a lot of this it might be worthwhile, and you could template the whole thing
for generality.

Generalising to n ranges would be an interesting programming exercise!

HTH

- Rob.