Hashing pointers as keys for unordered_map in C ++ STL

I published a similar quetion regarding the use of pointers as keys on maps in C ++ STL. How pointers are hashed in unordered_maps when used as keys. More specifically, if I define:

std::unordered_map< CustomClass*, int > foo; 

Will the default C ++ implementation of std :: hash execute these pointers? Is it safe to use? Is this a good practice?

+6
source share
1 answer

std::hash<T*> , but the details of how it works are implementation dependent. It will surely be safe to use, and I would consider it a good practice - as long as you need it as a key, and not the content of the object itself.

+6
source

Source: https://habr.com/ru/post/973333/


All Articles