Re: [Boost-users] [boost-users][multi-index] iterating though index keys

_______________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Igor R [boost.lists@gmail.com] Enviado el: jueves, 12 de junio de 2008 19:58 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] [boost-users][multi-index] iterating though indexkeys
Hi Joaquín,
for(Entries::iterator it_key=entries.begin(),end=entries.end();it_key!=end;){ // get all elements with key it_key->someForeignKey std::pairEntries::iterator,Entries::iterator values= entries.equal_range(it_key->someForeignKey); while(values.first!=values.second){ // process element ++values.first; } // next key is just that of the element right after the current value group it_key=values.second; }
Thank you! It seems to be exactly what I need. However, I'm not sure I got the principle right: how come that "next key is just that of the element right after the current value"? Is this the general behavior of equal_range - despite of the kind of the index (ordered/hashed, unique/non-unique)?
Yep, and the behavior of STL containers like std::multiset, for that matter. This is easily seen if you consider that indices of a multi_index_container (and STL containers) guarantee that elements with equivalent key are grouped together. So, if you hop from a group of same-key elements to the next you end up visiting all the keys present in the container. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (1)
-
JOAQUIN M. LOPEZ MUÑOZ