You always need to provide a function object mapping the key to a hash value even if this mapping is the identity. You can either define a specialization for std::hash<boost::uuids::uuid>
and have the std::unordered_map<K, V>
pick this one up automatically or you can parameterize the unordered map with additional template parameter for the function object type. In addition to the hash an equality operation is also needed but the default, using operator==()
is probably OK.
That said, the hash value won't accept a 128-bit integer unless your system has a built-in 128-bit integer type. The hash value needs to be a std::size_t
to be usable with the standard unordered containers. The complete list of requirements for std::hash<T>
specializations is listed in 20.8.12 [unord.hash]:
std::hash<X>
needs to be default constructible, copy constructible, and copy assignable.
std::hash<X>
needs to be swappable.
- It needs to provide two nested types
argument_type
for the key type and result_type
for the type of the hashed value with the latter being the same as std::size_t
.
- For the function the relation
k1 == k2
=> h(k1) == h(k2)
needs to be true where h
is the hashing function object.
So, you will need to define something along the lines of this:
namespace std {
template <>
struct hash<boost::uuids::uuid>
{
typedef boost::uuids::uuid argument_type;
typedef std::size_t result_type;
std::size_t operator()(boost::uuid::uuid key) const {
return transform_to_size_t(key);
}
};
}
where transform_to_size_t()
is the actual transformation you'll need to provide.
};