2009-06-30 95 views
3

我只是试验boost :: pool,看看它是一个更快的分配器,我正在使用的东西,但我不知道如何使用它与boost :: unordered_map:使用boost :: pool_allocator和boost :: unordered_map的语法是什么?

这是一个代码片段:

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

以下是编译错误,我得到:

错误3错误C2064:术语不计算为以2个为参数的C函数:\程序文件(x86)\提升\ boost_1_38 \ boost \ unordered \ detail \ hash_table_impl.hpp 2048

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

回答

7

看起来你错过了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; 

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

+0

谢谢,就是这样。 – 2009-06-30 03:22:26

相关问题