473,471 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6079

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: s | last post by:
Here is a snippet of my code: <code> list< MyClass * >outgoing_pool; MyClass* GetWaitingObject(string freq) { MyClass *temp_ptr = NULL; list<MyClass*>::iterator i;
8
by: ma740988 | last post by:
Consider: # include <iostream> using std::cout; using std::cin; using std::endl; # include <list> using std::list;
9
by: Youssef Mesri | last post by:
How can I erase one element over two in a list container? I have done something like this: 1- list<double> X; list<double>::iterator iter; for (int k=0; k<X.size() ; k++) { ++iter; if...
25
by: Markus Svilans | last post by:
Hi, There seems to be some functionality missing from the STL. I am iterating through a linked list (std::list) using a reverse iterator and attempting to erase certain items from the list. It...
16
by: Frank Neuhaus | last post by:
Hi I have some std list, I'd like to traverse. During the traversal, I want to conditionally delete some objects. My code for that is like this right now: for (std::list<myStruct>::iterator...
5
by: Christopher | last post by:
The situation is that a std::list<std::set<std::string is being iterated through. Upon certain criteria some sets become empty. I need to remove the empty sets from the list. Is it safe to...
7
by: TBass | last post by:
So I have a class: class Client { unsigned int ClientID; .... }; class MyListenSocket
4
by: TBass | last post by:
Hi, I've got a class that uses a std::list to store tags that need to be written out to a device. I've had no problem with the lists in terms of iterating and reading values. My problem is when...
9
by: Krice | last post by:
I get "list erase iterator outside range" message from MSVC with this function: int Level::Remove_Npc(Game_Object *o) { list <Game_Object *>::iterator pos; Game_Object *c; for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.