【发布时间】:2012-12-28 18:52:28
【问题描述】:
我正在尝试使用 dynamic_bitset 对象中的 set,但在运行时遇到断言失败:
a.out: boost/dynamic_bitset/dynamic_bitset.hpp:1291:
bool boost::operator<(const boost::dynamic_bitset<Block, Allocator>&,
const boost::dynamic_bitset<Block, Allocator>&)
[with Block = long unsigned int,
Allocator = std::allocator<long unsigned int>]:
Assertion `a.size() == b.size()' failed.
代码如下:
#include <iostream>
#include <set>
#include <boost/dynamic_bitset.hpp>
int main() {
typedef boost::dynamic_bitset<> bitset;
std::set<bitset> myset;
bitset x(2, 0);
bitset y(3, 1);
myset.insert(x);
myset.insert(y);
return 0;
}
我想知道为什么插入的dynamic_bitset 对象需要相同的大小。要让operator< 工作,它不能假设较短位集中的最高有效位隐式填充为零吗?
有什么方法可以让这组dynamic_bitsets 工作吗?
我也尝试了unordered_set,因为它不需要operator<,但它无法编译,因为dynamic_bitset 没有hash_value,我不知道该怎么写不使用其 to_ulong 成员函数,该函数仅适用于短位集。
【问题讨论】:
标签: boost set boost-dynamic-bitset