如何使用反向迭代器擦除()? [英] How can I erase() using a reverse iterator?
问题描述
嗨
我正在使用反向迭代器查看STL列表容器,但它看起来像
似乎erase()方法只接受普通的迭代器。是否有一个
类似的方法可以接受反向迭代器,或者是
有没有办法将反向迭代器转换为普通迭代器呢?
感谢您的帮助
B2003
Hi
I''m going through an STL list container using a reverse iterator but it
seems the erase() method only accepts ordinary iterators. Is there a
similar method that will accept reverse iterators or alternatively is
there a way to convert a reverse iterator to a normal one?
Thanks for any help
B2003
推荐答案
Boltar napsal:
Boltar napsal:
嗨
我正在使用反向迭代器查看STL列表容器但它似乎
似乎erase()方法只接受普通的迭代器。是否有一个
类似的方法可以接受反向迭代器,或者是
有没有办法将反向迭代器转换为普通迭代器呢?
感谢您的帮助
B2003
Hi
I''m going through an STL list container using a reverse iterator but it
seems the erase() method only accepts ordinary iterators. Is there a
similar method that will accept reverse iterators or alternatively is
there a way to convert a reverse iterator to a normal one?
Thanks for any help
B2003
我不知道您使用的是哪种类型的容器。无论如何,我认为你
没有一步擦除所有项目。因此迭代器将变为
无效。你应该使用
erase(container.rbegin(),container.rend());
或者simillar它应该可以工作。
I do not know which type of container are you using. Anyway I think you
are not erasing all items in one step. So iterators will become
invalid. You should use
erase(container.rbegin(), container.rend());
Or simillar and it should work.
Boltar写道:
Boltar wrote:
我正在使用反向通过STL列表容器迭代器,但它似乎
似乎erase()方法只接受普通的迭代器。是否有一个
类似的方法可以接受反向迭代器,或者是
有没有办法将反向迭代器转换为普通迭代器?
I''m going through an STL list container using a reverse iterator but it
seems the erase() method only accepts ordinary iterators. Is there a
similar method that will accept reverse iterators or alternatively is
there a way to convert a reverse iterator to a normal one?
reverse_iterator有一个成员函数base(),它将为您提供底层迭代器的
值。但要注意,底层的
迭代器指向不同的元素。这是一个关闭,精确的
关系船在标准[24.4.1 / 1]中给出:
& * (reverse_iterator(i))==& *(i - 1)
Best
Kai-Uwe Bux
The reverse_iterator has a member function base() that will give you the
value of the underlying iterator. Beware, however, that the underlying
iterator points to a different element. It''s off by one, and the precise
relation ship is given in the standard [24.4.1/1] as:
&*(reverse_iterator(i)) == &*(i - 1)
Best
Kai-Uwe Bux
1月25日,11:39,Kai-Uwe Bux< jkherci ... @ gmx.netwrote:
On 25 Jan, 11:39, Kai-Uwe Bux <jkherci...@gmx.netwrote:
底层迭代器的值。但要注意,底层的
迭代器指向不同的元素。这是一个关闭,精确的
关系船在标准[24.4.1 / 1]中给出:
& * (reverse_iterator(i))==& *(i - 1)
value of the underlying iterator. Beware, however, that the underlying
iterator points to a different element. It''s off by one, and the precise
relation ship is given in the standard [24.4.1/1] as:
&*(reverse_iterator(i)) == &*(i - 1)
谢谢。这听起来像是委员会决策的另一个胜利。
为什么他们认为一个人做出来有用呢?啊
好......
B2003
Thanks. That sounds like another triumph of committee decision making.
Why on earth did they think having it off by one would be useful? Ah
well....
B2003
这篇关于如何使用反向迭代器擦除()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!