Boost logo

Boost Users :

Subject: Re: [Boost-users] multi_index_comtainer questions
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2009-10-15 13:24:54


Vladimir Voronkov <voronkovv <at> mail.ru> writes:

> Hi again,
>
> Thanks for the answers, they helped my. Now I have come with some
> another probably stupid questions.
>
> I've changed the initial example by adding some attribute to the
> element. Let's say int.
>
> [...]
>
> typedef UsersContainer::nth_index<2>::type UsersSelected;
>
> This flag has not many possible values and most probably there will
> be many pairs in the container with the same value of this flag. Now
> I want to enumerate all values in the container with some specific
> value of this flag. There are many ways to do that.
> 1. Use lower_bound for getting iterator for the UsersSelected index.
> 2. implement own iterator that use some int value as a parameter.
>
> But the ideal solution would be to expose some kind of "view" of the
> container that behaves like list, so we could use it's iterator from
> begin() to end() taking only necessary elements.
>
> Is that possible?

The closest you can get to that, I guess, is to use
equal_range(n), which returns a pair of iterators
defining the range of elements with second==n (similar
as the "begin()" and "end()" iterators you're after.)

HTH,

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