I need a class that will work like C++ std::map. More specifically, I need such a behavior:
map< string, vector<int> > my_map;
Is it possible?
I need a class that will work like C++ std::map. More specifically, I need
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A dictionary is I believe what you want:
etc, etc
MSDN: http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
You can specify more or less any type as the key/value type. Including another dictionary, an array, or whatever:
So here each element in the Dictionary points to an array of strings.
To implement what you require (with the vector int), you would require a List as the value type:
It is worth noting that a Dictionary has no predefined order, whereas std::map does. If order is important, you may want to use SortedDictionary instead, which is almost identical in usage, but sorts on the key. All depends if you plan to iterate over the dictionary really.
Note however that if you use a class you created as the key, you will need to properly override GetHashCode and Equals.