|
-
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
|