473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling std::list::eras e(iterator pos) with a reverse_iterato r?

Hi,

Sorry if this has already been answered.

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

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

Dalbosco J-F wrote:
Hi,

Sorry if this has already been answered.

Given a std::list and a reverse_iterato r is there a way to erase the
element pointed to by the reverse_iterato r via the erase method?
Apparently the erase method takes a normal iterator and it fails to
compile if I pass it a reverse_iterato r. On the other hand, I don't
wan't to use myList.remove( *(myReverseIter ator)) for performance reason.
reverse_iterato r 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_iterato r is there a way to erase the
element pointed to by the reverse_iterato r via the erase method?
Apparently the erase method takes a normal iterator and it fails to
compile if I pass it a reverse_iterato r. On the other hand, I don't
wan't to use myList.remove( *(myReverseIter ator)) 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.ba se()) 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
9965
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
2870
by: ma740988 | last post by:
Consider: # include <iostream> using std::cout; using std::cin; using std::endl; # include <list> using std::list;
9
9099
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 (!(k%2)) { X.pop_back(); }
25
3890
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 is important that I iterate through the list backwards, because the items in it have to be processed in reverse order before erasing. However, there does not appear to be an std::list::erase() method defined for reverse iterators.
16
3596
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 it=myList.begin();it!=myList.end();) { if (it->someCondition) {
5
8652
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 iterate through a list and call list::erase( iterator ) in mid iteration?
7
2353
by: TBass | last post by:
So I have a class: class Client { unsigned int ClientID; .... }; class MyListenSocket
4
3900
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 I need to pop that value off the list when I'm done with it. In this case, I think the iterator is getting "lost" because I pop off the value it is pointing to at the end of this function. But how do I pop values off one at a time without the...
9
6719
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 (pos=npc_list.begin(); pos!=npc_list.end(); pos++) {
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.