reverse beginning & reverse end, may you explain?

I am reading about vectors and one part is confusing to me. The reverse begining seems to me more clear, but I need to make sure so I ask you:

http://www.cplusplus.com/reference/vector/vector/rbegin/
std::vector::rbegin
Returns a reverse iterator pointing to the last element in the vector (i.e., its reverse beginning).

So if I have 5 elements in vector: 1,2,3,4,5 , is it the 4 which is called the reverse beginning?

And about the reverse end, this was the confusion:
http://www.cplusplus.com/reference/vector/vector/rend/

Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (which is considered its reverse end).

Do they mean that this element does not exist or do they mean the element 5? As this one is the last one.
Last edited on
1 2 3 4 5

The beginning is 1.
The end is after the 5.

Let's reverse it.

5 4 3 2 1

The beginning is 5.
The end is after the 1.


(The way it all works underneath is a bit trickier than that, but from the user's point of view, it doesn't matter.)

Hope this helps.
Duoas: Sure it helps! Thanks.
But why they call the reverse beginning THE LAST ELEMENT IN THE VECTOR? That is confusing. Is it because this reverse iterator counts from right to left? So the most left one is the last and the most right one is the first?

std::vector::rbegin

Returns a reverse iterator pointing to the last element in the vector (i.e., its reverse beginning).
Last edited on
The vector does not change, so since 5 is the last of {1,2,3,4,5}, it is the last. Reverse iterator iterates differently from the forward iterator.
Topic archived. No new replies allowed.