473,804 Members | 3,138 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 6109

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
8654
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
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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
10077
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
9152
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
7620
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
6853
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.