I have an object that I want to travel in a continuous loop in a game. I have a series of coordinates in a std::vector
that I want to use as waypoints.
Is there any way to make an std::vector<T>::iterator
cyclic (also known as a circulator)?
The best I can come up with is to have two iterators and then whenever the first iterator is exhausted assign to it the value of the second (which would not be used to do anything else) but I am not even sure it will work - will the assignment operator copy whatever the iterator is using to hold the index or will it merely be referenced (and therefore will be useless after the second round)?
I want the object to travel the waypoint forever (unless it is destroyed but that doesn't happen in that method), but the iterator will only be called once for each frame and must return so that I can update the other objects in the game.
The solution must work on gcc and microsoft compiler (if it isn't possible to write it in standard C++).
See Question&Answers more detail:os