Define bitset size at initialization?

Boost has a dynamic_bitset you can use. Alternatively, you can use a vector<bool>, which (unfortunately) is specialized to act as a bitset. This causes a lot of confusion, and in general is considered a bad idea. But that’s how it works, so if that’s what you need, you might as well use it, I suppose.

Why doesn’t std::bitset come with iterators?

I don’t think there was ever an actual decision to exclude iterators from bitset. Rather, bitset is one of the classes that predates the proposal to add the original Standard Template Library to the C++ standard. When it was designed, essentially none of the standard library included iterators. Then, Stepanov’s library was proposed for addition, … Read more

Java BitSet Example

For the specific problem you mentioned: when you called bits2.set(1000001), you set the one millionth and first bit to true. Then when you intersected with bits1, which had the one million, 111 thousand, and 111st bit set, they had no bits in common. I think what you meant to do was bits2.set(0); // set the … Read more

tech