I've read a lot and couldn't find any answer to this issue. I have a multimap, which contains pairs of <Class object, enum class>
and using std::multimap.equal_range()
I'm getting the range of all of the duplicate keys in it. The next step is that I want to erase all but one of those duplicates. My following code erases all of them, leaving no pairs with the given key. Is there anyway that I can simply erase all but one of them?
void removeDuplicates( const string& strToRemove ) {
CFile obj (strToRemove, 0);
pair <multimap<CFile,Filetype>::iterator, multimap<CFile,Filetype>::iterator> ret;
ret = m_DirectoryMap.equal_range(obj);
for (multimap<CFile,Filetype>::iterator it=ret.first; it!=ret.second; ++it) {
it = m_DirectoryMap.erase(it);
}
}
Like I mentioned, with the following code if I have 3 pairs which have the same keys, they're all getting removed. I want to remove n-1 duplicates, not n.