473,498 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why doesn't erase method for map take key value as its parameter?

When I look at the C++ reference, erase method for map takes an
iterator as a parameter. I'm wondering why it takes iterator instead
of key value. Wouldn't it be faster to take key value and erase the
object? (because lookup operation using key value would be faster than
creating an iterator and iterate through the map?)

Jun 23 '07 #1
2 1502
yaru22 wrote:
When I look at the C++ reference, erase method for map takes an
iterator as a parameter. I'm wondering why it takes iterator instead
of key value. Wouldn't it be faster to take key value and erase the
object? (because lookup operation using key value would be faster than
creating an iterator and iterate through the map?)
When you look up a key, you are getting the iterator for that key. So
obviously deleteing using an iterator must be faster than looking to the
key to get the iterator and then using the iterator to delete.

john
Jun 23 '07 #2
yaru22 wrote:
When I look at the C++ reference, erase method for map takes an
iterator as a parameter. I'm wondering why it takes iterator instead
of key value. Wouldn't it be faster to take key value and erase the
object? (because lookup operation using key value would be faster than
creating an iterator and iterate through the map?)
Sorry... What reference are you looking at that doesn't have the 'erase'
member of 'std::map' that takes a key value?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 23 '07 #3

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

Similar topics

1
2340
by: C. Alexander | last post by:
Hey all. I have a whiteboard type program. I have 2 picturebox's (needed for their mousemove/mousedown events) Picture1.Picture = MyPicture ' Here is my hidden picture used to replace (on...
5
36374
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
26
5360
by: Pieter Thysebaert | last post by:
Hello, I've got a question conerning erasing key-value pairs from a std::map while iterating over it. According to the STL docs, erasing an element in a map invalidates all iterators pointing...
5
2400
by: Billy Patton | last post by:
I have a polygon loaded into a vector. I need to remove redundant points. Here is an example line segment that shows redundant points a---------b--------c--------d Both b and c are not...
2
1334
by: francisco lopez | last post by:
Yesterday I had a problem with a javascript to validate my form, but you helped my out yesterday and it works now perfectly!!! so thank you!!! the problem I have now is the following: I put...
2
3664
by: Nan Li | last post by:
Hello, I have seen people doing erase remove idiom like the following: ' vec.erase(remove_if(vec.begin(), vec.end(), is_odd<int>), vec.end() );' I remember Scott Meyers also uses this form in...
7
3288
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
1
1604
by: truedecembr | last post by:
Hi everyone, I am brand new to Java and not really even sure what I'm doing... I'm supposed to be writing a Timer class that is part of a stop watch application, and it seems to me that the program...
13
7453
by: thomas | last post by:
suppose I will delete an element pointed to by "iter". like this: vector<ints; for(vector<int>::iterator iter=s.begin(); iter!=s.end(); iter++){ if(*iter==3) s.erase(iter); ...
0
7125
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,...
0
7002
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...
0
7165
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,...
0
7203
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...
0
5462
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,...
0
4588
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...
0
3093
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...
0
1417
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 ...
0
290
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...

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.