std::unordered_map
을 tbb::concurrent_hash_map
으로 바꿉니다.tbd :: concurrent_hash_map의 값으로 std :: unique_ptr을 사용할 때 컴파일 오류가 발생했습니다.
내 원래 코드 :
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)));
는 그 소리 3.3와 잘 컴파일합니다. concurrent_hash_map에 unordered_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<...
이 연타 3.3의 버그인가? 많은 컨테이너에서 std :: unique_ptrs를 사용할 때 gcc 4.5에 유사한 오류가 있다는 것을 기억합니다. (위의 원래 코드는 예를 들어 gcc 4.5로 컴파일되지 않습니다.) 아니면 concurrent_hash_maps에 대해 뭔가를 놓쳤을까요? 마찬가지로 당신이 std::shared_ptr
를 사용하거나 독립 실행 형 벡터에 unique_ptr
의를 저장할 수 있습니다 해결
bool insert(const value_type& value);
:
std::vector<std::unique_ptr<V>> ptrs;
및 문서 tbb::concurrent_hash_map
에 따르면
tbb :: concurrent_hash_map과 같은 사운드는 constructible/move assignable 유형을 이동하는 대신 constructive/copy assignable을 복사해야 할 수도 있습니다. – mattnewport
@mattnewport 네, 맞습니다 - 문서 [링크] (http://www.threadingbuildingblocks.org/docs/help/reference/containers_overview/concurrent_hash_map_cls.htm)에 있습니다 - 놓쳐 버렸을 것입니다 "유형 키와 T 반드시 CopyConstructible 개념을 모델링해야한다. "- thanks – scmcduffee