I want to use a tbb::concurrent_hash_map with a key of std::tuple<A...> where A... will include boost unit types. The HashCompare struct I'm using at the moment looks like this:
template<typename K>
struct HashCompare {
static size_t hash( const K& key )
{
boost::hash<K> hasher;
return hasher(key);
}
static bool equal( const K& key1, const K& key2 ) {return key1 == key2;}
};
For all non boost unit types I tried this worked nicely but not so with boost units. I know that it is possible to extend the boost::hash function with custom types but I seem unable to do that. As i have quite a lot of units I wanted to do this with a template of the following form:
std::size_t hash_value(T const& t){
boost::hash<double> hasher;
return hasher(t.value());
}
Putting this function in the boost namespace or in the namespace where the units are defined didn't work.
How is it possible to extend the boost hashing function to custom types or write a template for the HashCompare::hash function that takes only boost units?
Indeed Boost Units does not have hash support. You can add it:
Smallest demo:
Live On Coliru
Prints
Using with
boost::hashin generic codeMake sure the overload is accessible on the point of instantiation. Enable argument dependent lookup (ADL):
Live On Coliru
Prints