I want to loop over each element in the multiset or unordered_set and during the loop, I could insert and remove the element. For example:
unordere_set<int> myset = { 1, 2, 3, 4 };
for (auto it = myset.begin(); it != myset.end(); ++it) {
myset.erase(*it);
// do something that needs to use the set without *it like in a recursion function that takes the reference of the set
myset.insert(*it);
}
I don't want to create a copy of the set since the set could be very large and it is not very efficient.