Static Map Initialization

U

utab

Dear all,

I am wondering whether there is a way to initialize map statically;

lets say I have

map<string, vector<string> > m;

I can initialize this way,

m["key1"].push_back(value1)
m["key1"].push_back(value2)
m["key2"].push_back(value1
m["key2"].push_back(value2)
..
..
..

Is there a way like in python(I guess most of you are familiar with
tables and dictionaries)

for example: for the above map

m=[(key1 value1), (key1 value2), (key2 value1), (key2 value2) ..... ]
// This is not existent in

// C++, I know but I think

// you got what I meant.

Regards
 
M

mlimber

utab said:
Dear all,

I am wondering whether there is a way to initialize map statically;

lets say I have

map<string, vector<string> > m;

I can initialize this way,

m["key1"].push_back(value1)
m["key1"].push_back(value2)
m["key2"].push_back(value1
m["key2"].push_back(value2)
.
.
.

Is there a way like in python(I guess most of you are familiar with
tables and dictionaries)

for example: for the above map

m=[(key1 value1), (key1 value2), (key2 value1), (key2 value2) ..... ]
// This is not existent in

// C++, I know but I think

// you got what I meant.

Regards

Yes. Use an Initializer class similar to the one for std::vector found
here:

http://groups.google.com/group/comp.lang.c++/msg/e2fe5982913d4414

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top