I have
std::list<multimap<std::string,std::string>::iterator> >
Now i have new element:
multimap<std::string,std::string>::value_type aNewMmapValue('foo1','test')
I want to avoid the need to set temp multimap and do insert to the new element just to get its iterator back so i could to push it back to the:
std::list<multimap<std::string,std::string>::iterator> >
can i somehow avoid this creation of the temp multimap. Thanks
You need to insert the key-value pair into a multimap before getting an iterator for it.
An iterator does not work by itself. If you are storing iterators from several different multimaps you probably need to store more than just an iterator in the list.
Perhaps:
a
pair<multimap<std::string,std::string>::iterator, multimap<std::string,std::string>::iterator>where first is the iterator and second is the end-iterator.a
pair<multimap<std::string,std::string>::iterator, multimap<std::string,std::string>*>where first is the iterator, and second is a pointer to the multimap that the iterator belongs to.some other kind of solution.
EDIT: I concur with Mykola Golubyev: It is often a bad idea to store iterators for a longer period of time, as the iterators may be invalidated.