2009-06-30 33 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

相關問題