Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2455 Discussions

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:


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