
Hi, On 4/2/07, "JOAQUIN LOPEZ MU?Z" <joaquin@tid.es> wrote:
Hi Guillaume
----- Mensaje original ----- De: Guillaume Lazzara <glazzara@gmail.com> Fecha: Lunes, Abril 2, 2007 5:13 am Asunto: [Boost-users] newbie's questions about multi_index Para: boost-users@lists.boost.org
Well, I'd say that the potential problem is not that es.second is modified when inside the loop, but rather that elements are repositioned between es.second-1 and es.second, so that the loop revisits them again, right?
A solution is to modify the loop so as to not use es.second but the immediately preceding position, just as this (beware, uncompiled code follows):
std::pair<EquivSet::iterator, EquivSet::iterator> es = contains.equal_range(*it); if(es.first!=es.second){ EquivSet::iterator last=es.second; --last; EquivSet::iterator next=es.first; EquivSet::iterator it_equiv; do{ it_equiv=next; ++next; contains.modify_key(it_equiv, update_equiv(nbEns)); }while(it_equiv!=last); }
Does this work?
Yes, it's perfect! Maybe I didn't see it, but IMHO I think you should include such an example in the multi_index documentation, it would be helpful. :)
- If I can choose between a std::set and a multi_index used as a set, which one should I use?
If you don't use any of the added functionality provided by Boost.MultiIndex (suboject searching, modify(), etc.) using std::set will yield faster compile times. Other than that, a multi_index_container with a single ordered_unique index is entirely equivalent to std::set.
Ok. Thanks again! -- Guillaume Lazzara Epita CSI 2008