c++ - boost 无序集不起作用

标签 c++ boost unordered-set

我是新手。我正在尝试实现 boost::unorder_set。这是代码:

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);
}

我收到以下错误:

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>&)

我的实现有什么问题?提前致谢。

最佳答案

unordered_multiset 不能从单个元素构造(它没有这样的构造函数)。试试这个:

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

您还需要正确包含 header :

#include <boost/unordered_set.hpp>

关于c++ - boost 无序集不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6092874/

相关文章:

c++ - 为什么 setf(ios::fixed) 跳过 double 中的第 6 个数字?

c++ - 如何使用boost从内存映射文件访问内存块?

c++ - unordered_map/unordered_set 中元组的通用哈希

c++ - 如何在 C++ 中只访问 unordered_set 的元素?

c++ - 为什么 unordered_set 不提供数组访问运算符

c++ - 大量数据的MySQL性能问题

c++ - 使用 std c++11 智能指针转换为非标量类型

c++ - 哪些常见的编程错误会导致在 epoll 边缘触发模式下卡住 CLOSE_WAIT?

C++ boost::asio 无法建立连接,因为目标机器主动拒绝它

c++ - 静态嵌套 bool 会帮助我禁用对某些类型的调用还是有更简洁的方法?