title: Get index in vector from reverse iterator
body: <p>I know how to get the index from a vector iterator, by subtracting the begin iterator from it. For example:</p>
  
  <pre><code>vector&lt;int&gt;::iterator it = find(vec.begin(), vec.end(), x);
  size_t position = it - vec.begin();
  </code></pre>
  
  <p>However, now I want to find the index of the last <code>x</code> in the vector. How can I get the real index from the reverse iterators? I've found the following that seems to work (edit: it doesn't) but maybe there is a better (more idiomatic or whatever..) way.</p>
  
  <pre><code>vector&lt;int&gt;::reverse_iterator it = find(vec.rbegin(), vec.rend(), x);
  size_t position = vec.size() - (it - vec.rbegin());
  </code></pre>