Alex Rivera | Logout

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

Asked 2012-09-07T20:17:34.047
9

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?

Edit
Report

1 Answer

1

My suggestion to you would be to wrap your multimap in a class and simply do the verification in the method where you add something into the map. The rest of the functions would simply pass through to the multimap's methods. It makes a lot of boiler plate code but if you ever need to do other types of verifications it'll be easier this way.

answered 2012-09-07T20:29:00.933

Your Answer