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 iterator from reverse_iterator as described in this answer.
But why above containers do not implement the erase member function with reverse_iterator parameter?
Is there any significant difference between iterator and reverse_iterator which makes such implementation difficult or it was not implemented for another reason?
The same question can be asked about virtually any container function: why isn't it implemented for reverse iterators? The answer is probably the simple fact that reverse iterator is easily convertible to regular iterator through base()
call. It makes more sense to place the burden of calling base()
on the user instead of almost doubling the number of container's functions by implementing a "reverse" version for every single one of them.
One can argue that it breaks the "generality" of containers in external contexts that process these containers through reverse iterators. But from the very beginning reverse iterators were designed as "different" and not necessarily compatible with normal iterators in all but most trivial contexts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With