I know that the following code is not correct, for std::vectors and more generally all STL containers:
std::vector<something>::iterator it = array.begin();
for(; it != array.end(); it++) {
...
array.erase(it);
...
}
because the iterator needs to be updated after erasing and element.
I was wondering if it's the same for a boost multi-index, e.g 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'd like to be sure to understand well 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 state that I can erase without invalidating the iterator. However I'm not sure if because I delete an element, another element that I would be supposed to visit during the iteration could be moved before the current iterator's position and never be visited (in other words, by erasing some elements during the iteration, am I still sure to go through all the elements?).
Thanks!