title: Obtaining an iterator from the element passed to a lambda when using std::find_if
body: <p>I am trying to simplify a recursive function that receives an iterator. Somewhere in the function it is necessary to search for an element matching a given condition in the range going from the iterator to the end of the vector. So, I thought I could use <code>find_if</code> as shown below:</p>
  
  <pre><code>typedef std::vector&lt;Foo&gt; FooVec;
  FooVec v;
  
  int f(FooVec::iterator it) {
    /* ... */
    auto it2 = std::find_if(it, end(v),
        [](const Foo&amp; foo) {
          auto foo_it = /* obtain the corresponding iterator for foo. */
          return f(foo_it) == 0;
        });
    /* ... */
  }
  </code></pre>
  
  <p>But the lambda function receives an element, not an iterator to the current element, so I cannot easily call <code>f</code> again. I could search for <code>foo</code> in <code>v</code> in order to get the iterator, but that would be inefficient. Alternatively I could just use a regular <code>for</code> loop with the iterators. But I was wondering whether there is the possibility to use <code>find_if</code> in this situation.</p>