tags:

views:

72

answers:

1
+3  A: 

To get access to N-th index you could use function get as follows:

std::pair< hmap::nth_index<3>::type::const_iterator,
           hmap::nth_index<3>::type::const_iterator > pit = 
  hmap.get<3>().equal_range(boost::make_tuple( partnerAge, false ) );

equal_range returns pair of iterators of N-th index. You will get range of elements that are satisfy the specified condition since your composite key is not unique. To iterate through that range you could use loop from the first iterator to the second iterator.

Consider using named indexes to use them as get<index_name>(), because specifying actual number is not very readable.

count has syntax similar to equal_range:

size_t cnt = hmap.get<3>().count(boost::make_tuple( partnerAge, false ) );
Kirill V. Lyadvinsky
Thanks, Kirill. I am using typedefs to simplify the indices but will incorporate tags too. Is the correct syntax to access the starting iterator in the range ...firstItr = pit->first? (That assignment isn't working. I'd like that iterator so I can increment it a random number of times to access a random Host that meets the composite key's criteria.)
Sarah
(The random number of times that firstItr is incremented will obviously be less than count so that it stays in range.)
Sarah
Nevermind, it's firstItr = pit.first
Sarah