During iteration over multimap I want to delete elements, but not only the element that the iterator points to.
for (vector<int> myVec : myVectors) { auto range = myMultiMap.equal_range(myVector); for (auto it = range.first; it != range.second; ++it) { // secondPair is another element of this multimap auto secondPair = getSecondPair(it, myMultiMap); if (condition) { it = myMultiMap.erase(it); auto finder = myMultiMap.find(secondPair); // how can I delete secondPair? } } }
Maybe this is the xy problem here, so let me explain what I need for this: what I'm trying to do is shorten the set of vector<int> . For each item there are related items of type MyPair . These related items are stored in an unordered multimedia.
typedef unordered_multimap < vector<int>, MyPair, SomeHash > MyMultiMap;
The set<vector <int> > element can be deleted if all related pairs in the multimag were successfully processed. This will not be successful for most of them, so most of them are expected to remain bundled. My idea was to remove elements from the multimap, and if there are no related elements in the multimag, this means that the element can be removed from the set. Here again, the problem arises of removing items from the set during iteration. Again, not only the one pointed to by the iterator.
Sadik source share