469,609 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

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 3358
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matthias Hildebrand | last post: by
2 posts views Thread by David Loo | last post: by
3 posts views Thread by Manuel Maria Diaz Gomez | last post: by
5 posts views Thread by EnTn | last post: by
3 posts views Thread by maheshr22 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.