Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid duplicate pairs / find a pair in multimap?

Tags:

c++

multimap

I have some (working) code that uses a multimap<string,string>. I'd like to change it to disallow duplicate values on the same key (obviously different values on the same key are fine, otherwise I wouldn't use a multimap).

Surprisingly the type doesn't seem to have a built-in way to avoid duplicates nor to find a key-value pair (only to find a key). But I figure someone on SO must have a ready-made workaround. Anyone?

like image 636
Qwertie Avatar asked Sep 07 '12 20:09

Qwertie


1 Answers

std::map<std::string, std::set<std::string>> would appear to have exactamondo the properties you are looking for (although inferior complexity to unordered_map and unordered_set).

like image 90
Puppy Avatar answered Sep 23 '22 07:09

Puppy