【发布时间】:2018-06-08 15:13:03
【问题描述】:
我在我的程序中使用tbb::concurrent_unordered_map 替换std::map,如下所示:
Before:
class KvSubTable;
typedef std::weak_ptr<KvSubTable> KvSubTableId;
std::map<KvSubTableId, int, std::owner_less<KvSubTableId> > mEntryMap;
现在,我用 tbb::concurrent_unordered_map 替换 std::map ,但编译时有一些错误:
tbb::concurrent_unordered_map<KvSubTableId, int, tbb::tbb_hash<KvSubTableId>, std::owner_less<KvSubTableId> > mEntryMap;
cpp/ext/amd64/include/tbb/internal/_tbb_hash_compare_impl.h:66:37: 错误:来自 'const 类型的无效 static_cast std::weak_ptr' 输入 'std::size_t
{aka long unsigned int}'
return static_cast(t) * internal::hash_multiplier;
我尝试了一些类似的解决方案,但它不起作用:
template <typename T>
inline bool operator==(const std::weak_ptr<T>& t, const std::weak_ptr<T>& u)
{
return !t.owner_before(u) && !u.owner_before(t);
}
那么,它是如何工作的,请帮助....
【问题讨论】:
-
无序地图不是地图,需要哈希函数。您还应该提供minimal reproducible example