1. ## Map of sets?

Hi,

I am trying to create an std::map, one of its elements is an std::set:

Code:
```string key = "a1";
set<int> setone;

map<string,set<int>> mapname;

setone.insert(1);
setone.insert(2);
setone.insert(3);

mapname.insert(key,setone);```
I'm unable to compile this, the insert() function isn't accepting the std::set as a parameter type.

How should I create a map which has std::sets as the second element type?

2. Why not just use the most common operator[] indexation technique:
mapname[key] = setone;
Or, if you won't use setone anymore from there, you can optimize this into:
mapname[key].swap(setone);
As for why it doens't work; because the function isn't supported. See here for a list of supported insert functions: http://www.sgi.com/tech/stl/Map.html

3. Thanks Evo for pointing that out.

Here is my full program:

Code:
```#include <iostream>
#include <map>
#include <set>
using namespace std;

int main()
{
map<string,set<int>> mapname;
set<int> setname;

setname.insert(1);
setname.insert(2);
setname.insert(3);

string key = "a1";

mapname[key] = setname; //compile error here

system ("pause");
return 0;
}```
I cannot get it to compile, it says because of the type. I'm confused on how to assign the set as the maps element.

Much appreciated

4. As a general rule it would be better to post the exact error message rather than paraphrasing something like "it says because of the type". Also, are you sure about which line is causing your error?

I think it's this one:
Code:
`	map<string,set<int>> mapname;`
You need a space between the angle brackets on the right side. It should be:
Code:
`	map<string,set<int> > mapname;`

5. My mistake, sorry for that.

I added the space, visual studio gives the following when I try to compile:

1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std:perator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std:perator <'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>:perator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=std::string
1> ]
I understand a std::set is implemented as a tree, could this be affecting things?

EDIT:

I tried using a typedef:

Code:
```#include <iostream>
#include <map>
#include <set>
using namespace std;

int main()
{
typedef map<string,set<int> > maptype;
maptype mapname;

set<int> setname;

setname.insert(1);
setname.insert(2);
setname.insert(3);

string key = "a1";

mapname[key] = setname;

system ("pause");
return 0;
}```
But still it fails:

1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std:perator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std:perator <'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>:perator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=std::string
1> ]

6. Beats me. I have no problem compiling it with g++, except for the missing space between the brackets, and the system("pause").

Maybe it's a bug in msvc++.

Edit: Oh, I just noticed that you didn't #include <string>. I'll bet that's the problem.

7. Yey it works now! I was stuck for ages trying to create this type structure.

Hey thanks so much.