473,796 Members | 2,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1589
newbie <mi******@yahoo .comwrote in news:1185514036 .005960.85290
@g12g2000prg.go oglegroups.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...@kostu r.netwrote:
newbie <mitbb...@yahoo .comwrote in news:1185514036 .005960.85290
@g12g2000prg.go oglegroups.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
3090
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 invalidating the iterator? This ominous statement in the STL "set" documentation makes me worried. I saw no similar statement on the "hash_multiset" docs. "Erasing an element from a set also does not invalidate any iterators, except, of course, for...
35
5482
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 : %d\n",sizeof(unsigned char)); printf("short : %d\n",sizeof(short)); printf("unsigned short : %d\n",sizeof(unsigned short)); printf("int : %d\n",sizeof(int));
4
11816
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 its parameters, I get: "Value does not fall within the expected range." How are people interacting with the Crystal Report viewer to set the parameters on a report? I haven't found any useful documentation at
14
4863
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 can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
89
6083
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 used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
8
1858
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 another problem that a member in a set cannot be deleted. I think I may be able to solve that problem if I can figure out the problem posted here. Thanks for your help. The sequence of (f1, f2) STL goes through is (7.7, 4.4), (7.7, 6.6),
130
6643
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 in the database show up with *15* decimal places and are ever so slightly off (in the example in the subject line, by about 2E-15). I'm not doing any operations on this column. It's just running a stored procedure which performs a pretty basic...
19
4211
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 = new CTestClientSocket(this, ip, port); pTemp->Connect(); m_collClients.push_back(pTemp);
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
9683
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
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
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...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
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
9054
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...
0
6792
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
5443
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
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.