我正在尝试使用set对象dynamic_bitset,但在运行时出现断言失败:
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 工作吗?
我也尝试了 anunordered_set因为它不需要,operator<但它无法编译,因为dynamic_bitset没有 ahash_value并且我不确定如何在不使用其to_ulong成员函数的情况下编写它,这仅适用于短位集。