2017-12-28 23 views
0

:tbb :: concurrent_unordered_map에서 weak_ptr을 사용하는 방법? 나는이 같은 내 프로그램에 <code>std::map</code>을 대체 할 <code>tbb::concurrent_unordered_map</code>을 사용하고

Before: 

class KvSubTable; 
typedef std::weak_ptr<KvSubTable> KvSubTableId; 
std::map<KvSubTableId, int, std::owner_less<KvSubTableId> > mEntryMap; 

을 지금, 나는 std::map을 대체 할 tbb::concurrent_unordered_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: error: invalid static_cast from type 'const std::weak_ptr' to type '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); 
} 

어떻게 작동합니까? 도와주세요 ....

+2

** 정렬되지 않은 **지도는지도가 아니며 해시 기능이 필요합니다. 또한 [mcve] –

답변

0

std::weak_ptr에 대한 해시 함수를 정의해야합니다. TBB 라이브러리에 대한 테스트에서 the example을 (를) 찾을 수 있습니다.