C++ Hash function for string in unordered_map

前端 未结 5 1587
被撕碎了的回忆
被撕碎了的回忆 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:17

    In my case it was really distraction.

    I had a type X for which I implemented hashing for const& X an utilized it somewhere with

    std::unordered_map m_map;
    

    Then I wanted to have another map which key are of the type X and did:

    std::unordered_map map_x;
    

    Notice the LACK of const on the second case.

提交回复
热议问题