如何在 tbb::concurrent_unordered_map 中使用weak_ptr
How to use weak_ptr in tbb::concurrent_unordered_map?
我正在使用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
{又名长无符号 int}'
返回 static_cast( t ( * 内部::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);
}
那么,它如何工作,请帮忙。
你需要为std::weak_ptr
定义一个哈希函数。您可以在 TBB 库的测试中找到该示例。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将重物插入std::map
- 使用通用值初始化 std::map,不重复
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- C++:当所有条目都保证是唯一时,替代 std::map
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 使用字符数组作为 Map 中的键
- C++如何创建 std::map
- C++ equivalent to Java Map getOrDefault?
- 从其他容器中移动构造"std::map"
- 如何使用 uint64_t 键类型从 std::map<int, std::string> 返回值?
- 将 std::map::emplace 与返回 shared_ptr 的函数一起使用是否正确?
- C++中 std::map 的运行时复杂度是多少?
- 为什么在 std::map 上移动无法将元素从一个映射移动到另一个映射