473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how does map take care invalid range for erase()?

Does standard say anything about this situation? or it is an undefined
behavior?

Thanks

------------------------------
map<int, inttest;
test[1] = 1;
test[2] = 2;
test[3] = 3;

test.erase(test.find(1), test.find(2)); // basically this is an
invalid range to erase.

map<int, int>::iterator pos = test.begin();
test.erase(pos, --pos); // another example of invalid range.
----------------------------

Jul 27 '07 #1
2 1567
newbie <mi******@yahoo.comwrote in news:1185514036.005960.85290
@g12g2000prg.googlegroups.com:
Does standard say anything about this situation? or it is an undefined
behavior?

Thanks

------------------------------
map<int, inttest;
test[1] = 1;
test[2] = 2;
test[3] = 3;

test.erase(test.find(1), test.find(2)); // basically this is an
invalid range to erase.
That's invalid? Perhaps you meant find(2) then find(1) ?
map<int, int>::iterator pos = test.begin();
test.erase(pos, --pos); // another example of invalid range.
----------------------------

Yep, they're both Undefined Behaviour. It's the programmer's
responsibility to ensure that the ranges passed to erase() (as in: the
first iterator is "less than" or equal to the second iterator.
Jul 27 '07 #2
On Jul 27, 6:38 am, Andre Kostur <nntps...@kostur.netwrote:
newbie <mitbb...@yahoo.comwrote in news:1185514036.005960.85290
@g12g2000prg.googlegroups.com:
Does standard say anything about this situation? or it is an undefined
behavior?
Thanks
------------------------------
map<int, inttest;
test[1] = 1;
test[2] = 2;
test[3] = 3;
test.erase(test.find(1), test.find(2)); // basically this is an
invalid range to erase.

That's invalid? Perhaps you meant find(2) then find(1) ?
Right, I meant the other way. test.erase(test.find(2), test.find(1));
>
map<int, int>::iterator pos = test.begin();
test.erase(pos, --pos); // another example of invalid range.
----------------------------

Yep, they're both Undefined Behaviour. It's the programmer's
responsibility to ensure that the ranges passed to erase() (as in: the
first iterator is "less than" or equal to the second iterator.
Thanks for the help

Jul 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kenneth Massey | last post by:
Is the following code guaranteed to work? I have a hashed set of pointers, which I would like to selectively delete from. Can I iterate through the set, deleting certain ones, without...
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
4
by: javatopia | last post by:
Hello, I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET page (C#). I can run the report via the admin console just fine. When I try to show the report, after setting up...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
8
by: JDT | last post by:
Hi, The last statement at the end of this post is to delete a set member 7.7. I set a break point inside ltstr::operator(). I found out that STL binary-seach the set twice. How come? I have...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.