Hashing pointers as Keys for unordered_map in C++ STL

前端 未结 1 642
长发绾君心
长发绾君心 2020-12-10 03:31

I posted a similar quetion regarding using pointers as Keys on maps in C++ STL. How are pointers hashed in unordered_maps when used as Keys. More specifically if I define:

相关标签:
1条回答
  • 2020-12-10 04:16

    std::hash<T*> is defined but the details of how it operates are implementation dependent. It will certainly be safe to use, and I'd consider it good practice - as long as it's the pointer you need as the key, and not the object contents itself.

    0 讨论(0)
提交回复
热议问题