| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting Map Position
Hello All, have another doubt in maps.
Suppose the following code: map<unsigned long long, cars> > carOne; cars anyCar; mapOne[anyKey] = anyCar; When I do the last command, is there anyway that I can find the position in mapOne where the anyCar was inserted without needing to use the mapOne.find(anyKey) command? Thanks in advance! |
|
#2
|
|||
|
|||
|
Re: Getting Map Position
I do not think so. Take a look at this thread on efficient map(/set) insertion.
__________________
C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way Kindly rate my posts if you found them useful
|
|
#3
|
||||
|
||||
|
Re: Getting Map Position
Quote:
On a side note, I would answer yes, it is possible. If you use lower_bound before you insert, then you should get an iterator. Either your iterator points to your actual object, and you don't need to find. Either the object is not in your map, you can use insertion with hint, and then, your object will be inserted at --iterator position. But to be quite frank, unless your application is absolutly time critical, all this extra development really isn't worth the performance gain, given the potential for disastrous bugs... (what if your map was empty when you lower bounded, what if --iterator is before begin etc...). Potential for bugs: 90%. I would just stick to map[key] = value; it = find(key); Potential for bugs: 10%. |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|