c++ - 使用 boost::pool_allocator 和 boost::unordered_map 的语法是什么?

标签 c++ stl boost unordered-map

我只是在试验 boost::pool 以查看它是否是我正在使用的东西的更快分配器,但我无法弄清楚如何将它与 boost::unordered_map 一起使用:

这是一个代码片段:

unordered_map<int,int,boost::hash<int>, fast_pool_allocator<int>> theMap;   
theMap[1] = 2;

这是我得到的编译错误:

错误 3 error C2064: term does not evaluate to a function takes 2 arguments C:\Program Files (x86)\boost\boost_1_38\boost\unordered\detail\hash_table_impl.hpp 2048

如果我注释掉 map 的使用,例如"theMap[1] = 2"然后编译错误消失。

最佳答案

您似乎缺少一个 template parameter .

template<typename Key, typename Mapped, typename Hash = boost::hash<Key>, 
     typename Pred = std::equal_to<Key>, 
     typename Alloc = std::allocator<std::pair<Key const, Mapped> > > 

第四个参数是比较的谓词,第五个是分配器。

unordered_map<int, int, boost::hash<int>,
     std::equal_to<int>, fast_pool_allocator<int> > theMap;

此外,但可能不是问题的原因,您需要在模板实例化结束时将两个“>”分开。

关于c++ - 使用 boost::pool_allocator 和 boost::unordered_map 的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1061543/

相关文章:

c++ - 将 boost 套接字放入 std::map

c++ - 编程原理与实践第 2 版第 8 章练习 1

c++ - 使用 IMediaSeeking 检测视频结尾

c++ - 关于设置容器

c++ - 我的 Phoenix lambda 表达式有什么问题?

c++ - Boost Asio - 如何知道处理程序队列何时为空?

c++ - 多线程和类?

c++ - 在 qt 中的 if 中对不同的进度条使用连接和断开连接

c++ - 如何在跟踪原始索引的同时压缩 vector (具有重复项)?

c++ - 在内存使用方面,c++ 中的 map 和 unordered_map 有什么区别吗?