【问题标题】:How to search hash_map containing reference_wrapper?如何搜索包含reference_wrapper的hash_map?
【发布时间】:2013-05-21 05:54:58
【问题描述】:

我正在使用 Intel TBB Concurrent Hash Map tbb::hash_map<std::string, std::reference_wrapper<Clusters>>,我想使用

搜索这个 hash_map
tbb::concurrent_hash_map<std::string, std::reference_wrapper<Clusters>>::accessor a;
if(table.find(a, operation.get().GetKey()))
{
    a->second.get().AddOperation(operation);
}

但它给出了error: no matching function for call to ‘std::reference_wrapper&lt;Clusters&gt;::reference_wrapper()。所以问题是reference_wrapper 没有find 需要的默认构造函数。有什么办法可以规避这个吗?

【问题讨论】:

  • 没有std::hash_map,并且std::unordered_map 没有名为accessor 的成员。这些是来自某个图书馆吗?
  • 对不起,我认为 std hash_map 有相同的成员。它来自英特尔 TBB 并发哈希映射
  • find()报错吗?它似乎不需要这样的构造函数。你能展示GetKey()的实现吗?
  • ParallelClusterCreator.h:27:54: required from here /usr/include/tbb/concurrent_hash_map.h:589:47: error: no matching function for call to ‘std::reference_wrapper&lt;Clusters&gt;::reference_wrapper()’ this is whole error message.
  • GetKey 很简单std::string GetKey() const { return key; }

标签: c++ hashmap tbb


【解决方案1】:

这似乎是find() 或其文档的实现中的一个错误。要么它需要映射类型为 DefaultConstructible 而它不应该,要么它没有记录它需要这个。

我认为这是您无法解决的问题。作为一种解决方法,您可以将指针存储在映射中而不是引用包装器中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    相关资源
    最近更新 更多