Relative Content

Tag Archive for c++algorithmvectoriteratorc++20

Iterate forwards or backwards depending on order of iterators

I have an std::vector with entries, and two entries a and b that are guaranteed to be in that vector. I’m using std::find to get iterators aIt and bIt in the vector for a and b. But I don’t know which of a and b comes first in the vector. Now I want to do something with all entries from a to b, for which I need to iterate from a to b, regardless of the order of these two. How can that be done ?