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

R

rudymoore

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
 
R

Rolf Magnus

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.
 
R

rudymoore

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?
 
H

Howard Hinnant

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?[/QUOTE]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top