From what I understand, the key in a value pair in an std::map cannot be changed once inserted. Does this mean that creating a map with the key template argument as const has no effect?
std::map<int, int> map1;
std::map<const int, int> map2;
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.
The answer to your title question is yes. There is a difference. You cannot pass a
std::map<int, int>to a function that takes astd::map<const int, int>.However, the functional behavior of the maps is identical, even though they’re different types. This is not unusual. In many contexts, int and long behave the same, even though they’re formally different types.