Boost logo

Boost Users :

Subject: [Boost-users] multi_index_container: replace() modifies my iterator
From: Nicolas Rannou (nicolas_rannou_at_[hidden])
Date: 2011-01-06 15:47:12


Hi all,

I'm pretty new in boost and I am experimenting an issue I can't understand.
It looks like the usage of "replace()" modifies the iterator I am
iterating on:

Here is a simple example:

it iterates properly if I do:

     Iterator it2, it3;
     boost::tuples::tie(it2, it3) = m_Container.get< CollectionID
>().equal_range( 30 );

     while( it2!= it3 )
       {
       int time = it2->TCoord;
       if( time < 500 ) // we want to change the collection ID in this case
         {
         Structure tempStructure(*it2);
         tempStructure.CollectionID = 40;
* //m_Container.get< CollectionID >().replace(it2, tempStructure);
comment this line*
         }
       ++it2;
       }

whereas if I call "replace()" the iterator value changes to "it3" then
it exists the loop:

     Iterator it2, it3;
     boost::tuples::tie(it2, it3) = m_Container.get< CollectionID
>().equal_range( 30 );

     while( it2!= it3 )
       {
       int time = it2->TCoord;
       if( time < 500 ) // we want to change the collection ID in this case
         {
         Structure tempStructure(*it2);
         tempStructure.CollectionID = 40;
* m_Container.get< CollectionID >().replace(it2, tempStructure);*
         }
       ++it2;
       }

the replace() method returns true.

I must be missing something but after reading the documentation and some
researches on the web I couldn't find the answer.

Any help/explanation would be greatly appreciated,
Thanks,

Nicolas



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