list<pair<int,int>> li{{5,6},{7,8},{9,10}};
for(auto it=li.rbegin();it!=li.rend();++it) {
cout << (*it).first << (*it).second << '\n';
li.erase(it);
}
error: no matching function for call to 'std::list<std::pair<int, int> >::erase(std::reverse_iterator<std::_List_iterator<std::pair<int, int> > >&)'
li.erase(it);
If the li.erase(it)
is replaced by li.remove(*it)
, the code works fine. However, all the value will be removed., and the algorithm become O(n2), instead of O(n), right?