On Fri, 20 Feb 2015 22:13:05 -0700, MikeCopeland <
mrc...@cox.net>
wrote:
> Is there a way to obtain an index value for an STL map? That is, if
>I use myMap.find(some_key) and obtain the container object, is there a
.find() returns an iterator, not the mapped value or the container
object. If you preserve the iterator by either not reusing it or
assigning its value to another iterator, you can access the map
element any time you want.
>way I can obtain a value from that iterator that allows me to (later)
>use the myMap.at() function to re-obtain the data object?
Once you have the iterator, you can obtain the map key with it->first.
If you save the key, you can use it later in a call to .at(). Unless
you have inserted additional elements into the map, using the iterator
seems to be more efficient.
> Or, is there a way to calculate and store (in the object) the index
>value I can use with myMap.at()?
What object are you talking about.
> My purpose here is that there are events where, after I've stored a
>map object via the key, I want to reacquire the object where I don't
>have access to the key: I've written another data object that doesn't
>contain the original map key.
Keys are unique in a map. If you stored a value in a map using the
key, then save the value of the key for later use in retrieving the
value. Storing another value in the map with a different key will not
change the way you can access the original value. Storing a different
value with the same key destroys the first value. There is no way to
get it back.
> Thoughts? TIA
>
>
>---
>This email has been checked for viruses by Avast antivirus software.
>
http://www.avast.com
--
Remove del for email