Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index] A multi_index where one index is a subset of the whole collection
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2012-04-22 13:19:36


Philipp Moeller <philipp.moeller <at> geometryfactory.com> writes:

>
> Hi,
>
> I've asked this question [1] two days ago on stackoverflow.com but haven't
> gotten any answer on it, yet. So I'll try it here.
>
> [1]
http://stackoverflow.com/questions/10217601/a-multi-index-where-one-index-is-a-subset-of-the-whole-collection
>
> If this is not possible out of the box, can I write my own indices for
> multi_index that would allow such functionality?

Hi Philipp,

No, unfortunately this is not possible, and the design of
Boost.MultiIndex makes it very difficult to implement coherently:
for one, how should iterator projection (http://tinyurl.com/7yyc9yr )
work when an element is not part of every index?

As a possible workaround, you can do as follows:

* Each time you "delete" an element from idx1, move it
to the back of the index. Keep an iterator idx1_end
to the first element in such a state, so that the
range of "active" elements of idx1 is [idx1.begin(),idx1_end).
* When you delete an element for good, check first if it
is *idx1_end that you're deleting; if so, increment
idx1_end before deletion.

Hope this helps,

Joaquín M López Muñoz
Telefónica Digital


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