【发布时间】:2013-10-30 20:02:49
【问题描述】:
我正在尝试用tbb::concurrent_hash_map 替换std::unordered_map。
我的原始代码:
typedef std::unique_ptr<V> V_ptr;
std::unordered_map<K, V_ptr> hm;
V_ptr v (new V);
K k;
hm.insert (std::make_pair (k, std::move (v)));
用 clang 3.3 编译得很好。将 unordered_map 切换为 concurrent_hash_map:
typedef std::unique_ptr<V> V_ptr;
tbb::concurrent_hash_map<K, V_ptr> hm;
V_ptr v (new V);
K k;
hm.insert (std::make_pair (k, std::move (v)));
导致错误:...stl_pair.h:105:21: error: call to deleted constructor of
'std::unique_ptr<...
这是 clang 3.3 中的错误吗?我记得在许多容器中使用 std::unique_ptrs 时 gcc 4.5 中存在类似的错误。 (例如,上面的原始代码不能使用 gcc 4.5 编译。)或者我错过了有关 concurrent_hash_maps 的一些内容?
【问题讨论】:
-
听起来像 tbb::concurrent_hash_map 可能需要复制可构造/可复制分配,而不仅仅是移动可构造/移动可分配类型。
-
@mattnewport 是的,你是对的 - 就在文档中 link - 一定错过了“Types Key 和 T 必须为 CopyConstructible 概念建模” - 谢谢
标签: gcc c++11 clang unique-ptr tbb