C++ Hash function for string in unordered_map

前端 未结 5 1585
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 00:46

It seems as if C++ does not have a hash function for strings in the standard library. Is this true?

What is a working example of using a string as a key in an unordered_

5条回答
  •  伪装坚强ぢ
    2021-02-05 01:15

    Actually, there is std::hash

    But there it is how you can use another hash function:

    struct StringHasher {
        size_t operator()(const std::string& t) const {
              //calculate hash here.
        }
    }
    
    unordered_map
    

提交回复
热议问题