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

Ale*_*ack 3 c++ boost stl unordered-map

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

这是一段代码:

unordered_map<int,int,boost::hash<int>, fast_pool_allocator<int>> theMap;   
theMap[1] = 2;
Run Code Online (Sandbox Code Playgroud)

这是我得到的编译错误:

错误3错误C2064:term不评估为带有2个参数的函数C:\ Program Files(x86)\ boost\boost_1_38\boost\unordered\detail\hash_table_impl.hpp 2048

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

180*_*ION 7

看起来你错过了一个模板参数.

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> > > 
Run Code Online (Sandbox Code Playgroud)

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

unordered_map<int, int, boost::hash<int>,
     std::equal_to<int>, fast_pool_allocator<int> > theMap;
Run Code Online (Sandbox Code Playgroud)

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