The following code example will not compile, however it can be made to compile by removing the const specifier before std::string as the unordered map key.
#include <unordered_map>
#include <utility>
#include <string>
#include <iostream>
int main()
{
int myint = 5;
std::unordered_map<const std::string, int*> map;
map.insert({"string", &myint});
std::cout << *map.at("string") << std::endl;
return 0;
}
Why does this code not compile when const std::string is used as a key, when std::string works?
mapandunordered_mapdiffer in this regard. It's a shame the duplicate doesn't seem to address this question.