Difference between these two codes?

So take a look at both these codes here:

(1) www.cplusplus.com/reference/vector/vector/rbegin/
(2) http://www.cplusplus.com/reference/iterator/reverse_iterator/operator++/

Link #1 declares a reverse iterator like so: std::vector<int>::reverse_iterator rit = myvector.rbegin();

While link #2 declares one like this: std::reverse_iterator<iter_type> rev_until

The codes are using two different iterator objects (declared differently) but are essentially doing the same exact thing: iterating backwards through a vector. In fact, link #2 seems to be a convoluted way of doing what link #1 is doing.

So my question is, what is even the point of std::reverse_iterator in the <iterator> library when there is already a nested reverse_iterator within the vector class? Is there some additional functionality that the former provides which the latter lacks?
Last edited on
It's the same type, only different names.

std::vector<int>::reverse_iterator is a typedef of std::reverse_iterator<std::vector<int>::iterator>
Last edited on
Oh snap! Did not see that coming.

Well, I guess we're done here then....
Topic archived. No new replies allowed.