I am trying to write a two-pass algorithm involving some old code. I want to move through a specific container twice, once in order and once in reverse order. Obviously, my first thought was to use iteratorand reverse_iterator, but it is strange that the developers of the container class that I use are not suitable for determining the working reverse_iteratorfor the container ( reverse_iteratorsit cannot be dereferenced here as it iteratorsmay be). I already have an algorithm that requires reverse_iterator.
My thought is to use the first pass iterator for the first part of the algorithm, and when I execute the push_frontelements algorithm in a new container and then iterate over the new container. This will require memory, which does not really matter in my application, but it made me think: are there any cleaner alternatives reverse_iteratorsin C ++, or should I spend time processing my algorithm using only forward iterators?
source
share