Search code examples
c++boostunordered-set

boost unordered set not working


I am new to boost. I am trying to implement boost::unorder_set. Here is the code:

struct point {
int x;
int y;};
bool operator==(point const& p1, point const& p2) {
return p1.x == p2.x && p1.y == p2.y; 
}
struct point_hash {{
size_t operator()(point const& p) const
{
    size_t seed = 0;
    hash_combine(seed, p.x);
    hash_combine(seed, p.y);
    return seed;
}};
int main() {
point pt;
unordered_multiset<point,point_hash> points(pt);
}

I get following error:

In instantiation of ‘boost::intrusive::do_pack<boost::intrusive::uset_defaults<point>, point_hash>’:
instantiated from ‘boost::intrusive::pack_options<boost::intrusive::uset_defaults<point>, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>’
instantiated from ‘boost::intrusive::make_hashtable_opt<point, false, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>’
instantiated from ‘boost::intrusive::make_unordered_multiset<point, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>’
instantiated from ‘boost::intrusive::unordered_multiset<point, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>’
boost_example.cpp:29:   instantiated from here
error: no class template named ‘pack’ in ‘struct point_hash’
boost_example.cpp: In function ‘int main()’:
boost_example.cpp:29: error: no matching function for call to ‘boost::intrusive::unordered_multiset<point, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>::unordered_multiset(point&)’
note: candidates are: boost::intrusive::unordered_multiset<point, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>::unordered_multiset(const boost::intrusive::unordered_multiset<point, point_hash, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none, boost::intrusive::none>&)

What is wrong with my implementation? Thanx in advance.


Solution

  • unordered_multiset cannot be constructed from a single element (it has no such a constructor). Try this:

    point pt;
    boost::unordered_multiset<point,point_hash> points;
    points.insert( pt );
    

    Also you need properly included header:

    #include <boost/unordered_set.hpp>