Custom Hash Functions
In order to use custom objects in std::unordered_map, a custom hash function must be defined. This function takes a const reference to the custom type and returns a size_t
struct X{int i,j,k;}; struct hash_X{ size_t operator(const X &x) const{ return hashThe user defined function can be used as is in std::unordered_map, by passing it as a template parameter
std::unordered_mapOr can be set as the default hash function by specializing the std::hash function
namespace std { template <> class hashRead more about this topic: Unordered Associative Containers (C++)
Famous quotes containing the words custom and/or functions:
“The imagination of man is naturally sublime, delighted with whatever is remote and extraordinary, and running, without control, into the most distant parts of space and time in order to avoid the objects, which custom has rendered too familiar to it.”
—David Hume (17111776)
“Let us stop being afraid. Of our own thoughts, our own minds. Of madness, our own or others. Stop being afraid of the mind itself, its astonishing functions and fandangos, its complications and simplifications, the wonderful operation of its machinerymore wonderful because it is not machinery at all or predictable.”
—Kate Millett (b. 1934)