|
Boost Users : |
Subject: Re: [Boost-users] multi_index_container: replace() modifies my iterator
From: Nicolas Rannou (nicolas_rannou_at_[hidden])
Date: 2011-01-07 12:36:13
Thanks, that is what I was suspecting.
Is there already something in boost to do what I intend to do?
If not, which strategy would you recommend to by pass this issue?
I got some ideas but nothing straight forward and I would like it to
be as efficient as possible.
Thanks again,
Nicolas
On Jan 6, 2011, at 11:31 PM, Steven Watanabe wrote:
> AMDG
>
> On 1/6/2011 12:47 PM, Nicolas Rannou wrote:
>> 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:
>> <snip>
>>
>> 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,
>
> The position of the element can change when you
> change the key. The iterator continues to point to
> the same element, but the element has moved.
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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