Because the phonebook
has a composite key, it is sorted on given names within last names. So you can call the regular std::equal_range
on the first search result to match a dummy phonebook_entry
that has only "Dorothy" defined:
int main()
{
phonebook pb; // no initializer_list support for multi_index_container yet
pb.insert({ "White", "Dorothy", "1" });
pb.insert({ "Black", "Dorothy", "2" });
pb.insert({ "White", "John", "3" });
pb.insert({ "Black", "John", "4" });
pb.insert({ "White", "Dorothy", "5" });
auto const w = pb.equal_range("White");
auto const d = phonebook_entry{"", "Dorothy", ""};
auto const wd = std::equal_range(w.first, w.second, d, [](phonebook_entry const& lhs, phonebook_entry const& rhs) {
return lhs.given_name < rhs.given_name;
});
std::for_each(wd.first, wd.second, [](phonebook_entry const& pbe) {
std::cout << pbe.phone_number << "\n";
});
}
Live example that will print for "White, Dorothy" the phone numbers 1 and 5.