【问题标题】:How to use weak_ptr in tbb::concurrent_unordered_map?如何在 tbb::concurrent_unordered_map 中使用weak_ptr?
【发布时间】: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);
}

那么,它是如何工作的,请帮助....

【问题讨论】:

标签: c++ tbb weak-ptr


【解决方案1】:

您需要为std::weak_ptr 定义一个哈希函数。您可以在 TBB 库的测试中找到 the example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 2015-01-21
    相关资源
    最近更新 更多