471,831 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

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 5960

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
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.