Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the syntax to use boost::pool_allocator with boost::unordered_map?

I'm just experimenting with boost::pool to see if its a faster allocator for stuff I am working with, but I can't figure out how to use it with boost::unordered_map:

Here is a code snippet:

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

Here is the compile error I get:

Error 3 error C2064: term does not evaluate to a function taking 2 arguments C:\Program Files (x86)\boost\boost_1_38\boost\unordered\detail\hash_table_impl.hpp 2048

If I comment out the use of the map, e.g. "theMap[1] = 2" then the compile error goes away.

like image 357
Alex Black Avatar asked Nov 18 '25 00:11

Alex Black


1 Answers

It looks like you are missing a 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> > > 

The fourth parameter is the predicate for comparison, the fifth is the allocator.

unordered_map<int, int, boost::hash<int>,
     std::equal_to<int>, fast_pool_allocator<int> > theMap;

Also, but probably not the cause of your issue, you need to separate the two '>' at the end of the template instantiation.

like image 102
1800 INFORMATION Avatar answered Nov 19 '25 14:11

1800 INFORMATION