【问题标题】:Whats the syntax to use boost::pool_allocator with boost::unordered_map?将 boost::pool_allocator 与 boost::unordered_map 一起使用的语法是什么?
【发布时间】:2010-11-06 21:17:57
【问题描述】:

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

这是一个代码sn-p:

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" 然后编译错误就消失了。

【问题讨论】:

    标签: c++ stl boost unordered-map


    【解决方案1】:

    您似乎缺少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;
    

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

    【讨论】:

      猜你喜欢
      • 2017-12-27
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      相关资源
      最近更新 更多