How to determine if a particular key is unique in a multimar?

I have multimap<key_type,value_type> , and I would like to know if a particular key will be displayed on the map no more than once.

I know that I can call multimap.equal_range(key) to find an iterator for the beginning and end of the range containing key , but I would like to know if there is only one element between range.first and range.second .

Is there a better way than incrementing the value of range.first to see if it is equal to range.end ? Since multimap::iterator is bidirectional, this is not a huge deal to undo the increment, but it seems messy for that.

+6
source share
1 answer

Can you check std :: multimap :: count (key) == 1?

+7
source

Source: https://habr.com/ru/post/920288/


All Articles