Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if vector<bool> is actually a vector of bits and not bytes?

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)?

like image 751
Bonz0 Avatar asked Jan 14 '13 21:01

Bonz0


1 Answers

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).

like image 182
Mark B Avatar answered Sep 27 '22 22:09

Mark B