【发布时间】:2020-10-16 07:40:15
【问题描述】:
我想使用带有std::tuple<A...> 键的tbb::concurrent_hash_map,其中A... 将包括升压单元类型。我目前使用的 HashCompare 结构如下所示:
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;}
};
对于所有非升压单元类型,我都试过了,但对于升压单元则不然。我知道可以使用自定义类型扩展 boost::hash 函数,但我似乎无法做到这一点。由于我有很多单位,我想使用以下形式的模板来做到这一点:
std::size_t hash_value(T const& t){
boost::hash<double> hasher;
return hasher(t.value());
}
将此函数放在boost 命名空间或定义单位的命名空间中不起作用。
如何将 boost 散列函数扩展为自定义类型或为 HashCompare::hash 函数编写模板,该函数只接受 boost 单元?
【问题讨论】:
标签: c++ templates boost boost-units boost-functional