equal_range on one key, lower/upper bound on another in boost multi_index_container composite_key
-
27-05-2021 - |
Question
Suppose I have the following:
struct Person
{
std::string mName;
Birthday mBirthday;
};
using namespace boost::mult_index;
typedef multi_index_container<
Person,
ordered_non_unique<
composite_key<
Person,
member<Person, std::string, &Person::mName>,
member<Person, Birthday, &Person::mBirthday>
> // composite_key
> // ordered_non-unique
> PersonContainer; // mult_index_container
PersonContainer personContainer;
...
std::pair<PersonContainer::iterator, PersonContainer::iterator> similarPeople
= personContainer.equal_range(boost::make_tuple("Bob","01/15/65"));
This would give me an iterator range where each iterator pointed to a Person named 'Bob' born on '01/15/65'.
What if I want an iterator range that gave me all the people in the container named 'Bob' but born between '01/01/65' and '01/31/65'? This is effectively an equal_range on 'Bob' but a lower and upper bound on birthdays. Is this possible? If so please explain how?
Thanks!
Solution
The range you want is [lower_bound(make_tuple("Bob","01/01/65"))
,upper_bound(make_tuple("Bob","01/31/65"))
).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow