Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Use multimap to Create Associative Containers with Duplicate Keys

The Standard Library's multimap container is very similar to the map associative container—except that it allows duplicate keys. Find out how this functionality makes multimap more useful than it seems.


advertisement
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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap