I know that the following code is incorrect for std :: vectors and, as a rule, for all STL containers:
std::vector<something>::iterator it = array.begin(); for(; it != array.end(); it++) { ... array.erase(it); ... }
because the iterator must be updated after erasing and the element.
I was wondering if this would be the same for boost multi-index, for example, would something like the following be correct or not:
my_index::iterator it = index.get<0>().begin(); for(; it != index.get<0>().end(); it++) { ... index.erase(it); ... }
I would like to accurately understand the following paragraph of the documentation: http://www.boost.org/doc/libs/1_51_0/libs/multi_index/doc/tutorial/indices.html#guarantees which seems to indicate that I can erase without canceling an iterator. However, I'm not sure that since I am deleting an element, another element that I would have to visit during the iteration could be moved to the current position of the iterator and never be visited (in other words, erasing some elements during the iteration, Iām all Still sure to go through all the elements?).
Thanks!
source share