
n a
previous column, I discussed the Standard Library’s
map associative container. But this was only one half the story. The Standard Library also defines a
multimap container, which is similar to map except that it allows duplicate keys. This property makes
multimap more useful than it seems at first: think of a phone book in which the same person may have two or more phone numbers, a file system in which multiple
symbolic links are mapped to the same physical file, or to a DNS server that maps several URLs to the same IP address. In such cases, you’d want to do something like this:
//note: pseudo code
multimap <string, string> phonebook;
phonebook.insert("Harry","8225687"); //home
phonebook.insert("Harry","555123123"); //work
phonebook.insert("Harry"," 2532532532"); //mobile
The ability to store duplicate keys in
multimap heavily affects its interface and usage.

How to create an associative container with non-unique keys?

Use the multimap container defined in the <map> library.