468,497 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,497 developers. It's quick & easy.

Calling std::list::erase(iterator pos) with a reverse_iterator?

Hi,

Sorry if this has already been answered.

Given a std::list and a reverse_iterator is there a way to erase the
element pointed to by the reverse_iterator via the erase method?
Apparently the erase method takes a normal iterator and it fails to
compile if I pass it a reverse_iterator. On the other hand, I don't
wan't to use myList.remove( *(myReverseIterator)) for performance reason.

Can anyone help?
Thanks by advance,
JF.
Aug 3 '06 #1
3 5808

Dalbosco J-F wrote:
Hi,

Sorry if this has already been answered.

Given a std::list and a reverse_iterator is there a way to erase the
element pointed to by the reverse_iterator via the erase method?
Apparently the erase method takes a normal iterator and it fails to
compile if I pass it a reverse_iterator. On the other hand, I don't
wan't to use myList.remove( *(myReverseIterator)) for performance reason.
reverse_iterator has a method called "base" which will give you back
the base iterator. You can use this.

Chris

Aug 3 '06 #2

Dalbosco J-F wrote:
Hi,

Sorry if this has already been answered.

Given a std::list and a reverse_iterator is there a way to erase the
element pointed to by the reverse_iterator via the erase method?
Apparently the erase method takes a normal iterator and it fails to
compile if I pass it a reverse_iterator. On the other hand, I don't
wan't to use myList.remove( *(myReverseIterator)) for performance reason.
Apologises for two posts in a short period of time, I just realised my
previous post had an error.

In the standard, you'll notice that:

Iterator base() const; returns "current", while operator* is defined
as:

" iterator tmp = current; return *--tmp;"

Therefore, *reverse_it and *(reverse_it.base()) aren't the same thing.
*reverse_it and *(--reverse_it.base()) are.

Reverse iterators are strange..

Chris

Aug 3 '06 #3
Azumanga wrote:
Reverse iterators are strange..
Here's a good article that explains the relationships among the
different types of iterators:

http://www.ddj.com/dept/cpp/184401406

--
Marcus Kwok

Aug 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by s | last post: by
8 posts views Thread by ma740988 | last post: by
9 posts views Thread by Youssef Mesri | last post: by
25 posts views Thread by Markus Svilans | last post: by
16 posts views Thread by Frank Neuhaus | last post: by
5 posts views Thread by Christopher | last post: by
7 posts views Thread by TBass | last post: by
4 posts views Thread by TBass | last post: by
9 posts views Thread by Krice | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.