3

我只是在试验 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”,那么编译错误就会消失。

4

1 回答 1

8

看起来您缺少模板参数

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;

此外,但可能不是您的问题的原因,您需要在模板实例化的末尾分隔两个“>”。

于 2009-06-30T03:17:07.880 回答