gpt4 book ai didi

c++ - 如何使用 tbb 实现并发哈希表,将键映射到不同类型的值?

转载 作者:行者123 更新时间:2023-11-28 02:29:41 31 4
gpt4 key购买 nike

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

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::variant 可能会更好如果 boost 在您的项目中可行。

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

关于c++ - 如何使用 tbb 实现并发哈希表,将键映射到不同类型的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29344682/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com