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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date