将 boost::pool_allocator 与 boost::unordered_map 一起使用的语法是什么?

发布于 2024-07-25 17:09:11 字数 438 浏览 2 评论 0原文

我只是在尝试使用 boost::pool 来看看它是否是我正在使用的东西的更快的分配器,但我不知道如何将它与 boost::unordered_map 一起使用:

这是一个代码片段:

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

这是编译错误我得到:

错误 3 错误 C2064:术语不计算为采用 2 个参数的函数 C:\Program Files (x86)\boost\boost_1_38\boost\unordered\detail\hash_table_impl.hpp 2048

如果我注释掉使用地图,例如“theMap[1] = 2”,那么编译错误就会消失。

I'm just experimenting with boost::pool to see if its a faster allocator for stuff I am working with, but I can't figure out how to use it with boost::unordered_map:

Here is a code snippet:

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

Here is the compile error I get:

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

If I comment out the use of the map, e.g. "theMap[1] = 2" then the compile error goes away.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-08-01 17:09:11

您似乎缺少模板参数

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;

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

It looks like you are missing a 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> > > 

The fourth parameter is the predicate for comparison, the fifth is the allocator.

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

Also, but probably not the cause of your issue, you need to separate the two '>' at the end of the template instantiation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文