Boost Users :
Subject: Re: [Boost-users] [multi_index] doing insert() within iteration over equal_range() result?
Date: 2008-10-23 10:50:15
Prometheus Prometheus escribió:
> Hi all,
> i have the following problem:
> i use multi_index like this
> std::pair<Plugins::pEvents::index::type::iterator,Plugins::pEvents::index::type::iterator> range;
> range = this->events.get().equal_range(boost::make_tuple(event,condition));
> // CALL an event handler!
> this->callEventHandler(range.first); // << this shows just how it works, its not exactly my code
> within the callEventHandler and its called functions its possible that the event handler wants to register new events which results to this:
> The problem is OR can be, that the insert modifies the indices which modify the range.first iterators and thus a ++range.first results in an invalid "next" element
> this makes sense and i think most of you know this and had this problem already
> Does anyone have a good idea/solution how to solve this situation correctly so that the range i received will be valid?
I think the easiest solution is to save copies of the iterators in range
start the loop:
range = this->events.get().equal_range(boost::make_tuple(event,condition));
// CALL an event handler!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
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