Why don't C ++ containers implement erasure (reverse_iterator position)?

I looked at some C ++ containers (vector, deque, list, map, set) and found that none of them implement

erase(reverse_iterator position) 

There is a way to get an iterator from reverse_iterator, as described in this.

But why don't the containers above implement the erase member function with reverse_iterator parameter?

Is there a significant difference between an iterator and reverse_iterator, which makes this implementation difficult or was not implemented for another reason?

+7
c ++ c ++ 11
source share
1 answer

You can ask the same question about almost any container function: why is it not implemented for reverse iterators? The answer is probably the simple fact that the reverse iterator is easily converted to a regular iterator via a call to base() . It makes sense to place the burden on calling base() on the user instead of almost doubling the number of container functions by implementing the "reverse" version for each of them.

It can be argued that it violates the "generality" of containers in external contexts that process these containers using reverse iterators. But from the very beginning, reverse iterators were designed as "different" and are not necessarily compatible with regular iterators in all but the most trivial contexts.

+4
source share

All Articles