How comes that std::hash does not exist for const std::string?
#include <string>
#include <functional>
int main() {
std::hash<std::string> hasher1; // works
std::hash<const std::string> hasher2; // does not work
}
As expected, I can use the regular std::string specialization for example in a hash map:
#include <string>
#include <functional>
#include <unordered_map>
int main() {
std::unordered_map<const std::string, int, std::hash<std::string>> a;
}
I feel like there is a better reason than "Well, they just didn't do it" to the const specialization missing. What is it?
unordered_map<const std::string, int>instead of justunordered_map<std::string, int>?unordered_mapin the second snippet works as well. I am just surprised that those specializations did not exist.