Hello Jeff, Jeff Holle ha escrito:
I'm using boost::multi_index obtained via CVS on Fri Jun 29 12:30:03 EDT 2007.
In my application, I'm using a multi_index container that has one ordered index. Call the container Present and the index YIndex.
I'm at the point in which I need to erase an element which returns a YIndex::iterator. Its important that I know the neighbors of the element erased with respect to the YIndex.
I know that the element which I look for in the container must exist, so I have an assert that will fail if the searched for element isn't found.
If I code it like this: YIndex& index=m_present.get<0>(); YIndex::iterator iter = index.begin(); for (;iter!=index.end();++iter) if (m_future.top().getEdges().first == iter->getEdge()) break; assert(iter!=index.end()); iter = index.erase(iter); The assert goes off the 4th time this code runs.
If I change the code to this: Present::iterator iter = m_present.begin(); for (;iter!=m_present.end();++iter) if (m_future.top().getEdges().first == iter->getEdge()) break; assert(iter!=m_present.end()); iter = m_present.erase(iter);
The application runs to completion, but since I need YIndex::iterators I can't code what is needed by my application.
I'm assuming that calling erase corrupts the ordered index. What do I have to do to correct this?
The two snippets of code you show are entirely equivalent, in the sense that Present inherits the functionality of its first index, YIndex. In particular YIndex::iterator is the *same type* as Present::iterator, so I'm puzzled by the fact that you're observing different behaviors --from the code you're showing, using one or the other variation cannot possibly make any difference whatsoever. Could you please check your code for some other differences you might have not noticed when doing the switch from one version to the other? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo