C ++ Iterator and Reverse Iterator

I am writing iterator(actually this is const_iteratorfor my current object and I also want to create reverse_const_iterator.

I looked around to see how to do this, and I came across this :

Note that with a reverse iterator, the reverse version does not point to the same element in the range, but to the one preceding it. This is so, in order to organize the past Range element: An iterator pointing to the end element in the range, if it is reversed, it changes to indicate the last element (not past it) of the range (this would be the first element of the range, if in the reverse order) . And if the iterator to the first element in the range is inverse, the reverse iterator points to the element before the first element (this would be the last element of the range, if in the reverse order).

Is this what happens from the point of view of users, or when you act out reverse_iterator, does it not abstract by providing you with a value / link to the object that you think points to? Are these just implementation details?

My understanding was:

for(i = obj.rbegin(); i != obj.rend(); i++)

was equivalent

for(i = obj.begin(); i != obj.end(); i++)

. , *i . ?

+5
1

, . , , , . . std::reverse_iterator - base, .

std::reverse_iterator :

: &*(reverse_iterator(i)) == &*(i - 1)

base - , :

it++;
lst.erase(it.base());

, , :

it++;
std::list<int>::reverse_iterator(lst.erase(it.base()));
+5

All Articles