Boost logo

Boost Users :

From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-06-12 15:58:59

De: boost-users-bounces_at_[hidden] [boost-users-bounces_at_[hidden]] En nombre de Igor R [boost.lists_at_[hidden]]
Enviado el: jueves, 12 de junio de 2008 19:58
Para: boost-users_at_[hidden]
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::pair<Entries::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

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at