Composite key syntax in Boost MultiIndex
Posted
by Sarah
on Stack Overflow
See other posts from Stack Overflow
or by Sarah
Published on 2010-04-19T18:12:08Z
Indexed on
2010/04/19
18:43 UTC
Read the original article
Hit count: 482
Even after studying the examples, I'm having trouble figuring out how to extract ranges using a composite key on a MultiIndex container.
typedef multi_index_container<
boost::shared_ptr< Host >,
indexed_by<
hashed_unique< const_mem_fun<Host,int,&Host::getID> >, // ID index
ordered_non_unique< const_mem_fun<Host,int,&Host::getAgeInY> >, // Age index
ordered_non_unique< const_mem_fun<Host,int,&Host::getHousehold> >, // Household index
ordered_non_unique< // Age & eligibility status index
composite_key<
Host,
const_mem_fun<Host,int,&Host::getAgeInY>,
const_mem_fun<Host,bool,&Host::isPaired>
>
>
> // end indexed_by
> HostContainer;
My goal is to get an iterator pointing to the first of the subset of elements in HostContainer hmap
that has age partnerAge
and returns false
to Host::isPaired()
:
std::pair< hmap::iterator,hmap::iterator > pit = hmap.equal_range(boost::make_tuple( partnerAge, false ) );
I think this is very wrong.
- How/Where do I specify the iterator index (which should be 3 for age & eligibility)? I will include other composite keys in the future.
- What exactly are the two iterators in
std::pair
? (I'm copying syntax from an example that I don't understand.) - I would ideally use
std::count
to calculate the number of elements of agepartnerAge
that are eligible (returnfalse
toHost::isPaired()
). What is the syntax for extracting the sorted index that meets these requirements?
I'm obviously still learning C++ syntax. Thanks in advance for any help.
© Stack Overflow or respective owner