470,815 Members | 1,287 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Static Map Initialization

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

May 12 '06 #1
1 7388
utab wrote:
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....fe5982913d4414

Cheers! --M

May 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Luther Baker | last post: by
1 post views Thread by philwozza | last post: by
8 posts views Thread by Per Bull Holmen | last post: by
20 posts views Thread by JohnQ | last post: by
6 posts views Thread by gs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.