473,320 Members | 1,982 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,320 software developers and data experts.

map::insert gets a hint. What about map::find?

I'm often find-ing the same string in a map<string,xxx>

I want to pass a hint to map::find but was disappointed to find that
only map::insert takes the hint.

Why would map::insert take a hint but not map::find?

Thanks,

Rudy

Jul 23 '05 #1
3 3818
ru*******@hotmail.com wrote:
I'm often find-ing the same string in a map<string,xxx>

I want to pass a hint to map::find but was disappointed to find that
only map::insert takes the hint.

Why would map::insert take a hint but not map::find?


If you already have an iterator to the element, there is no point in using
find.

Jul 23 '05 #2
>If you already have an iterator to the element, there is no point in

I do not already have an iterator to the element. I know my example
seems to indicate I do, but the actualy case is much to complicated to
post here. Plus it's irrelevent to my question:

Why would map::insert take a hint but not map::find?

Jul 23 '05 #3
In article <11**********************@l41g2000cwc.googlegroups .com>,
ru*******@hotmail.com wrote:
If you already have an iterator to the element, there is no point in


I do not already have an iterator to the element. I know my example
seems to indicate I do, but the actualy case is much to complicated to
post here. Plus it's irrelevent to my question:

Why would map::insert take a hint but not map::find?


Perhaps we didn't think of it. Or perhaps it is too easy to do
something like:

if (guess->first != key)
guess == m.find(key);
// guess now points to either key or end()

A key question is: For the semantics you desire, can it be done more
efficiently internal to map than you can do externally? Or is such an
external implementation sufficiently complicated that it is likely that
clients will get it wrong? If the answer is no, then adding such
functionality would merely be a convenience function and bloat the
interface with dubious benefit (see std::string). If the answer is yes,
then you likely have a good point, and I would like to see a proposal
before the LWG immediately (time grows short for C++0X).

The "insert with hint" functionality as currently specified is also of
dubious usefulness, and I hope to make it more useful for C++0X. There
will be a paper in the post-Lillehammer mailing addressing this issue.

-Howard
Jul 23 '05 #4

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

Similar topics

4
by: Matthias Hildebrand | last post by:
Hello, std::map< int, MyClass*> mymap; it = mymap.find( somekey ) // here happen bad things if( it != mymap.end() ) { // do something useful with it->second } else
2
by: David Loo | last post by:
Hi, I want to use a map to store a list of strings and i dont want a duplicate string added to the list. how can I go about this using the STL map? Thank you. loodav@hotmailDOTcom replace...
3
by: Manuel Maria Diaz Gomez | last post by:
Hi everybody, This should be trivial, but I just can't see it. The following statement in a method doesn't work for me: (there's only one entry in myMap) map<const char*, int>::const_iterator...
5
by: EnTn | last post by:
Hi Everyone... I've been trying to use a std::map to do some storage. Basically, i'm storing double values using a Key Object. The Key object is quite simple and is just a pair of int's...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
2
by: cyndykoobs | last post by:
I have run into a problem that I cannot seem to figure out regarding a method call to STL map::find(). When the key value can't be found in the map (this is an expected scenario), it returns end()...
6
by: Benny the Guard | last post by:
Been working on a project that compiles, links, and runs fine on 32-bit windows. Now trying to migrate to 64-bit windows. On debug build it works fine. However, on release build the std::map::find...
3
by: maheshr22 | last post by:
Hey Heres what i want to do: I want to create a map which has <string, vector<vector<int>>>. The string is always unique. What i need to do is, as i read each string from a file, i compare it...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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

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.