This line :
size_t hashVal0 = std::hash<std::string>{}(strInput);
equal these two lines:
std::hash<std::string> szHash;
size_t hashVal = szHash(strInput);
The hashVal0 == hashVal == true.
this is why need {} in first line:
std::hash<KeyType>{}: This creates an instance of thestd::hash<KeyType>class. The{}is used to call the default constructor.(key): This calls theoperator()method on the instance ofstd::hash<KeyType>, passingkeyas the argument.
more deep dive:
The syntax std::hash<KeyType>(key) might look like it’s invoking a function, but std::hash<KeyType> is not a function—it’s a class template. Therefore, std::hash<KeyType>(key) would be trying to call a constructor of std::hash<KeyType> that takes an argument of type KeyType, but no such constructor exists.
5096



被折叠的 条评论
为什么被折叠?



