Boost logo

Boost Users :

From: Jeff Holle (jeffreyholle_at_[hidden])
Date: 2007-09-10 11:50:18


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?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net