Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Liu__shitao
Beginner
67 Views

How to use weak_ptr as key in tbb::concurrent_unordered_map?

I am using tbb::concurrent_unordered_map to replace std::map in my program like this:

Before:

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

Now, I use tbb::concurrent_unordered_map to replace std::map , but it has some compile errors:

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<tianji::master::KvSubTable>' to type 'std::size_t     {aka long unsigned int}'                                                                                                                                                     180      return static_cast<size_t>( t ) * internal::hash_multiplier;
181                                      ^

then, I have try some solutions like this , but it does not work.

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);
}

So, how can it work, please help....

0 Kudos
0 Replies
Reply