如何使用将键映射到不同类型的值的 tbb 实现并发哈希 table?

How to implement a concurrent hash table with tbb which maps key to values of different types?

我的要求是实现一个具有2个字段的并发哈希table,第一个是int类型的键,而第二个存储整数、字符和结构类型的数据。显而易见的方法是使用

定义哈希映射
typedef concurrent_hash_map<int, void> myTable;

但它给出了以下错误:

/usr/include/c++/4.8/bits/stl_pair.h:102:11: error: instantiation of ‘std::pair<_T1, _T2>::second’ as type ‘void’
    _T2 second;                /// @c second is a copy of the second object
       ^
/usr/include/c++/4.8/bits/stl_pair.h:102:11: error: ‘std::pair<_T1, _T2>::second’ has incomplete type
/usr/include/c++/4.8/bits/stl_pair.h:102:11: error: invalid use of ‘void’
/usr/include/c++/4.8/bits/stl_pair.h:112:26: error: forming reference to void
   _GLIBCXX_CONSTEXPR pair(const _T1& __a, const _T2& __b)

是否有解决方案或替代方案?

你不能这样使用 void

你的意思可能是typedef concurrent_hash_map<int, void*> myTable;

如果 boost 在您的项目中可行,您可能最好使用 boost::variant

//assuming myStruct is your "structure"
typedef boost::variant<int,char,myStruct> myValue;
typedef concurrent_hash_map<int, myValue> myTable;