|
Boost Users : |
Subject: Re: [Boost-users] [Multi Index Container]: Retrieving a set by ordered non-unique criteria?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-07-05 13:28:53
AMDG
On 07/04/2012 07:46 AM, Steve Hibbert wrote:
>
> I'm a newbie use of Multi Index Containers, apologies if this question is facile. I have read through the Boost online documentation but am still a bit stumped.
>
> I have a container that contains shared pointers to instants of a custom object type (in this case, financial market orders).
>
> The container has an ordered-non-unique index defined by a member function of the object. Specifically it is the object's state code, an integer. At any point in time, I would expect several objects with a state value of 1, several with 2, etc.
>
> I need to pull back the set of objects in a particular state, to a set. I intend to use the set in testing to 'do something' with one random object in that set, but to all intents and purposes I just need to get the shared pointer to an item in State=1.
>
> How would I pull back the set (or analogous container) of objects that are in State=1?
>
> I am thinking that I first get a reference to the index in question, which is fine. Would I then do a find(), and would that find() operation return a set-like object? Or, would I need to do a lower_bound() and upper_bound() operation to find the two enclosing iterators, and then copy all shared-pointers-to-objects to a std::set, and then operate on the set as normal?
>
Use equal_range. It's equivalent to lower_bound + upper_bound
and also works on hashed indices. If you really need
a separate container rather than a pair of iterators,
then you'll have to copy the range, as you suggest.
> Thanks in advance for assistance with this, help is greatly appreciated.
>
In Christ,
Steven Watanabe
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