title: How do you use find_if along with reverse_iterator on a C-style array?
body: <p>To search the first occurence of a element in a C-Array with POD elements, one ease can do this with <code>std::find_if(begin, end, findit)</code>. But I needed the last occurence. <a href="https://stackoverflow.com/a/9850249/237483">This answer</a> gave me the idea that this can be done with <code>std::reverse_iterator</code>. Thus I tried:</p>
  
  <pre><code>std::find_if(std::reverse_iterator&lt;podtype*&gt;(end),
               std::reverse_iterator&lt;podtype*&gt;(begin),
               findit);
  </code></pre>
  
  <p>This gave me the error:</p>
  
  <blockquote>
    <p>cannot convert 'std::reverse_iterator&lt; xyz* > ' to 'xyz*' in assignment</p>
  </blockquote>
  
  <p>Do you have an idea how to do it this way or do you know a better solution?</p>
  
  <p>This is the code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;algorithm&gt;
  
  struct xyz {
      int a;
      int b;
  };
  
  bool findit(const xyz&amp; a) {
      return (a.a == 2 &amp;&amp; a.b == 3);
  }
  
  int main() {
      xyz begin[] = { {1, 2}, {2, 3}, {2, 3}, {3, 5} };
      xyz* end = begin + 4;
  
      // Forward find
      xyz* found = std::find_if(begin, end, findit);
      if (found != end)
          std::cout &lt;&lt; "Found at position "
                    &lt;&lt; found - begin
                    &lt;&lt; std::endl;
  
      // Reverse find
      found = std::find_if(std::reverse_iterator&lt;xyz*&gt;(end),
                           std::reverse_iterator&lt;xyz*&gt;(begin),
                           findit);
      if (found != std::reverse_iterator&lt;xyz*&gt;(end));
          std::cout &lt;&lt; "Found at position "
                    &lt;&lt; found - std::reverse_iterator&lt;xyz*&gt;(end)
                    &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>And the <a href="http://codepad.org/0LM93Hhv" rel="noreferrer">compiler error on codepad.org</a></p>