I don't see how it = someset.insert(removedValue); can work. These are the only overloads I see for set.insert():
Code:
pair<iterator, bool> insert(const value_type& x);
iterator insert(iterator it, const value_type& x);
void insert(const value_type *first, const value_type *last);
Originally Posted by
MSDN
The second member function returns insert(x), using it as a starting place within the controlled sequence to search for the insertion point. (Insertion can occur in amortized constant time, instead of logarithmic time, if the insertion point immediately follows it.)
So shouldn't the code be more like this:
Code:
void someFunction(std::set<int> &someset);
...
for (std::set<int>::iterator it = someset.begin(); it != someset.end(); ++it) {
int removedValue = *it;
it = someset.erase(it);
--it;
someFunction(someset);
it = someset.insert(it, removedValue);
}