I need to store a dynamic array of bits.
The C++ reference page on vector< bool > has the following information:
The storage is not necessarily an array of
bool
values, but the library implementation may optimize storage so that each value is stored in a single bit.
How do I make sure that my program that uses vector<bool>
does in fact store bits in a vector instead of boolean values (bytes)?
Don't try to do that. Instead, use boost::dynamic_bitset
which clearly indicates what you actually want. The vector<bool>
optimization actually creates a number of possibilities for bugs, for example when using iterators (because it usually returns a proxy object).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With