title: std::for_each working on more than one range of iterators
body: <p>The lambda notation has made stl algorithms more accessible. I am still learning to decide when it's useful and when to fall back to good old fashioned for-loops.
  Often, it becomes necessary to iterate over two (or more) containers of the same size, such that corresponding elements are related, but for some reason are not packed into the same class.</p>
  
  <p>A function using a for-loop to achieve that would look like this:</p>
  
  <pre><code>template&lt;typename Data, typename Property&gt;
  void foo(vector&lt;Data&gt;&amp; data, vector&lt;Property&gt;&amp; prop) {
      auto i_data = begin(data);
      auto i_prop = begin(prop);
      for (; i_data != data.end(); ++i_data, ++i_prop) {
          if (i_prop-&gt;SomePropertySatistfied()) {
              i_data-&gt;DoSomething();
          }
      }
  }
  </code></pre>
  
  <p>In order to use for_each, I need a version of it that handles multiple ranges; something like:</p>
  
  <pre><code>template&lt;typename InputIter1, typename InputIter2, typename Function&gt;
  Function for_each_on_two_ranges(InputIter1 first1, InputIter1 last1, InputIter2 first2, Function f) {
      for (; first1 != last1; ++first1, ++first2) {
          f(*first1, *first2);
      }
      return f;
  }
  </code></pre>
  
  <p>With this version, the above code would look like this:</p>
  
  <pre><code>template&lt;typename Data, typename Property&gt;
  void foo_two_ranges(vector&lt;Data&gt;&amp; data, vector&lt;Property&gt;&amp; prop) {
      for_each_on_two_ranges(begin(data), end(data), begin(prop), [](Data&amp; d, Property&amp; p) {
          if (p.SomePropertySatistfied()) {
              d.DoSomething();
          }
      });
  }
  </code></pre>
  
  <p>Is there an equivalent way of achieving the same result using stl algorithms?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I found the exact answer to my question in the form of boost::for_each running on boost::range. I added the answer, with example code for the sake of completeness.</p>