boost无序集不工作
boost unordered set not working
我是新手。我正在尝试实现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>&)
我的实现有什么问题?提前Thanx。
unordered_multiset
不能由单个元素构造(它没有这样的构造函数)。试试这个:
point pt;
boost::unordered_multiset<point,point_hash> points;
points.insert( pt );
您还需要适当包含的标题:
#include <boost/unordered_set.hpp>
您只需要将一个参数传递给unordered_multiset<>,boost::hash做剩下的工作,因为它知道如何散列自定义数据类型。
#include "boost/unordered_set.hpp"
struct point {
int x;
int y;
// The following ctor isn't required, but I'm biased against garbage in tests
point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
};
bool operator==(point const& p1, point const& p2) {
return p1.x == p2.x && p1.y == p2.y;
}
std::size_t hash_value(point const& p){
std::size_t seed =0;
boost::hash_combine(seed, p.x);
boost::hash_combine(seed, p.y);
return seed;
}
int main() {
boost::unordered_multiset<point> points;
struct point p;
points.insert(p);
points.insert(p);
return 0;
}
相关文章:
- QSqlquery prepare()和bindvalue()不工作
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- 递归无序映射
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 不确定无序映射是如何工作的
- 无法使无序映射工作
- 通过无序集访问类数据无法正常工作
- boost无序集不工作
- 无序映射它的工作原理