advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 5/5 | Rate this item | 2 users have rated this item.
 

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.

  Next Page: Presenting the Problem


Page 1: IntroductionPage 3: Finding a Single Value
Page 2: Presenting the Problem 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs