Hi,
I am wondering what the safe way to delete a map entry through its
iterator. There is a example from the book of Nicolai Josuttis:
for(map::iterator itr=myMap.begin();itr !=myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
itr++;
}
is there other way to do so or this is the only way?
thx. 6 10730 we*****@yahoo.com wrote:
Hi,
I am wondering what the safe way to delete a map entry through its
iterator. There is a example from the book of Nicolai Josuttis:
for(map::iterator itr=myMap.begin();itr !=myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
itr++;
}
is there other way to do so or this is the only way?
thx.
This is a very slight improvment.
for(map::iterator itr=myMap.begin();itr !=myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
++itr;
}
It definitely not the only way, but it is the best way as far as I know.
Do you have a problem with it?
john
On Feb 23, 5:28 pm, John Harrison <john_androni...@hotmail.comwrote:
wenm...@yahoo.com wrote:
Hi,
I am wondering what the safe way to delete a map entry through its
iterator. There is a example from the book of Nicolai Josuttis:
for(map::iterator itr=myMap.begin();itr !=myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
itr++;
}
is there other way to do so or this is the only way?
thx.
This is a very slight improvment.
for(map::iterator itr=myMap.begin();itr !=myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
++itr;
}
It definitely not the only way, but it is the best way as far as I know.
Do you have a problem with it?
john
No. Thank for pointing out the pre-increment of iterator. I almost
forgot about it.
On Fri, 23 Feb 2007 22:28:02 GMT in comp.lang.c++, John Harrison
<jo*************@hotmail.comwrote,
>This is a very slight improvment.
for(map::iterator itr=myMap.begin();itr !=myMap.end()) { if(itr->value == something) myMap.erase(itr++); else ++itr; }
In all optimization, YMMV. But I think this is another slight
improvement. Also some typos corrected.
for(map::iterator itr=myMap.begin(); itr !=myMap.end(); )
{
if(itr->first == something)
itr = myMap.erase(itr);
else
++itr;
}
However, some implementations may not support the return iterator from
map::erase().
David Harmon wrote:
On Fri, 23 Feb 2007 22:28:02 GMT in comp.lang.c++, John Harrison
<jo*************@hotmail.comwrote,
>>This is a very slight improvment.
for(map::iterator itr=myMap.begin();itr !=myMap.end()) { if(itr->value == something) myMap.erase(itr++); else ++itr; }
In all optimization, YMMV. But I think this is another slight
improvement. Also some typos corrected.
for(map::iterator itr=myMap.begin(); itr !=myMap.end(); )
{
if(itr->first == something)
itr = myMap.erase(itr);
else
++itr;
}
However, some implementations may not support the return iterator from
map::erase().
Returned iterator from map::erase is not required by the standard so
this code is non-standard. Apparently this is a somewhat controverial topic.
john
John Harrison wrote:
David Harmon wrote:
>On Fri, 23 Feb 2007 22:28:02 GMT in comp.lang.c++, John Harrison <jo*************@hotmail.comwrote,
>>>This is a very slight improvment.
for(map::iterator itr=myMap.begin();itr !=myMap.end()) { if(itr->value == something) myMap.erase(itr++); else ++itr; }
In all optimization, YMMV. But I think this is another slight improvement. Also some typos corrected.
for(map::iterator itr=myMap.begin(); itr !=myMap.end(); ) { if(itr->first == something) itr = myMap.erase(itr); else ++itr; }
However, some implementations may not support the return iterator from map::erase().
Returned iterator from map::erase is not required by the standard so
this code is non-standard. Apparently this is a somewhat controverial
topic.
It is not _yet_ required by the standard: The current draft N2134 for C++0X
provides that erase() returns an iterator for all containers.
Best
Kai-Uwe Bux
On Sat, 24 Feb 2007 07:13:59 GMT in comp.lang.c++, John Harrison
<jo*************@hotmail.comwrote,
>Returned iterator from map::erase is not required by the standard so this code is non-standard. Apparently this is a somewhat controverial topic.
Darn it, I can't keep it all straight. I was just looking at the C++0x
draft, and it's gonna be standard eventually. http://www.open-std.org/jtc1/sc22/wg...2006/n2135.pdf This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mudcat |
last post by:
Howdy,
I have a simple combox that I have commands entered into which looks
like this:
"""This is a list with the commands to be run in rotisserie
fasion."""
self.comList =...
|
by: Andrew DeFaria |
last post by:
I created the following .sql file to demonstrate a problem I'm having.
According to the manual:
If |ON DELETE CASCADE| is specified, and a row in the parent table
is deleted, then InnoDB...
|
by: Robert Schneider |
last post by:
Hi to all,
I don't understand that: I try to delete a record via JDBC. But I always
get the error SQL7008 with the error code 3. It seems that this has
something to do with journaling, since the...
|
by: nick_faye |
last post by:
Hi guys,
i'm still a newbie in using MS Access and in VB programming. I am
using DAO connection from my VB to access the entries on my MS Access
table. I am having trouble in editting and...
|
by: John Rivers |
last post by:
Hello,
I think this will apply to alot of web applications:
users want the ability to delete a record in table x
this record is related to records in other tables
and those to others in...
|
by: Jeff User |
last post by:
Hello
..NET 1.1, VS 2003, C# & asp.net
I have tried to follow msdn instructions and samples but I can not get
an event to fire for this button on the datagrid.
There has to be something obvious...
|
by: dan |
last post by:
Hi,
I have a table like this:
ColA ColB
22 Drink
22 Eat
22 Spill
23 Drink
23 Eat
|
by: Wannabe |
last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page reloads except the row I am
trying to delete is still there. I believe it is...
|
by: tvks |
last post by:
Dear all,
I have an xml file called abc.xml. It is of the following format.
<?xml version="1.0" encoding="ISO-8859-1"?>
<contacts>
<entry uri="sip:vinayg@company.org">...
|
by: Riun |
last post by:
when I use the following code:
Dim stDocName as String
stDocName = "DELETE FROM WHERE =" & txtID
DoCmd.RunSQL stDocName
the whole row will be deleted from the table. I only want the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |