【发布时间】:2012-01-27 03:08:00
【问题描述】:
我一直在使用 stackoverflow,甚至是非常非常好的Dr. Dobbs article,但我找不到这个问题的明确答案。
What are the shortcomings of std::reverse_iterator? 问题答案的一部分说这可能根本不可能。
std::list::reverse_iterator it = list.rbegin();
while( it != list.rend() )
{
int value=*it;
if( some_cond_met_on(value) )
{
++it;
list.erase( it.base() );
}
else
{
++it;
}
}
PS:我知道还有其他替代方法,例如 erase_if(),但我正在寻找这个特定问题的答案。
【问题讨论】: