STL容器逆向时删除方法
std::deque<int> q;
for(int i(0);i<5;++i)q.push_back(i);
for (auto pos = q.rbegin();pos != q.rend(); ++pos)
{
if(*pos == 3)
{
q.erase(--(pos.base()));
break;
}
}
std::for_each(q.begin(),q.end(),[](const int &i){std::cout<<i<<std::endl;});
原理:&*(reverse_iterator(i)) == &*(i - 1)
参考:http://www.drdobbs.com/cpp/184401406
还没有评论,来说两句吧...