A map inside a map

Hello.

How do you store a map value inside a map?

Here's my code:

 
	map<map<string, string>, int> Name;
Last edited on
Before I answer your question, I need to know what are you trying to achieve by this.
Well, I just wanted to know how to put values. I'm thinking of having a map where you have a name seperated into 2 strings(last name, first name) using map and having an extension of their age.
You can try map<string, map<string, int>>, but boost::multi_index_container suits that better.

Or have a map<pair<string, string>, int>. Every approach has drawbacks depending on what are you trying to do.
Last edited on
How is map<string,map<string, int>> different from map<map<string, string>, int>?
Remember, that map keys are (a) constant, (b) goes inside [].

And if we take into account how maps store key-value pairs, we will see that it makes it poor choice for keys... Well, there is a good rule of thumb: do not use containers as keys for associative containers.

Basicly you can have some unexpected things as
1
2
3
bad_map[{{"Bill", Smith}}] = 10;
bad_map[{{"john", Smith}}] = 11;
bad_map[{{"john", Smith}, {"Bill", Smith}}] = 12;
Yes. That three different pair of key/value.
Okay. I get now thank you.
Topic archived. No new replies allowed.