-
March 23rd, 2009, 04:45 AM
#1
How to convert c++ std::list element to multimap iterator
Hello all
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.
-
March 23rd, 2009, 05:56 AM
#2
Re: How to convert c++ std::list element to multimap iterator
If you are storing a list of multimap iterators, then the original values MUST exist in a multimap somewhere, otherwise the iterator to it will be invalid.
Also be aware that if the multimap should re-assign it's internal storage then all of your iterators in the list will be invalidated.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
March 23rd, 2009, 06:49 AM
#3
Re: How to convert c++ std::list element to multimap iterator
Originally Posted by umen
Hello all
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.
I'm trying to understand the reason behind you trying to convert an iterator in the first place.
If you recall, map::insert() that takes a single argument of value_type() returns a pair,
so you can do something like
Code:
#include <iostream>
#include <string>
#include <list>
#include <map>
using namespace std;
int main()
{
typedef multimap<string, string>::value_type valType;
typedef multimap<string, string>::iterator iterType;
// sample data
multimap<string, string> mMap;
list<iterType> List;
valType viter("Key", "Value");
List.push_back(mMap.insert(viter));
return 0;
}
without creating a temp map, so there's no need for conversion here.
But I could be totally wrong about what you're asking here.
If this was way off,
then maybe use std:air? (I haven't tried it yet) to make a bridge?
or something like that...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|