Jump to content
Posted 21 November 2012 - 02:21 PM
Posted 21 November 2012 - 02:41 PM
Posted 21 November 2012 - 02:51 PM
Posted 21 November 2012 - 05:46 PM
If you need a large vector of bits, this representation is much more compact than an array of bools, because each bool will need to take up at least one full byte in memory. If you don't need a large vector of bits, there is no point whatsoever.
Posted 21 November 2012 - 06:28 PM
Edited by Qanael, 21 November 2012 - 06:30 PM.
Posted 21 November 2012 - 07:38 PM
Posted 21 November 2012 - 09:29 PM
Posted 21 November 2012 - 09:35 PM
Interestingly, std::vector<bool> is required by the standard to be a specialization that packs the bools into single bits for the very reason of saving space. It was included in the standard as an example of how to write proxying containers. I believe many committee members later regretted that.
The std::bitset container also provides a bit-oriented container, complete with boolean operations and a cunning string-serialization interface. Guaranteed to take only one bit per bit, and when compiled with release-level optimization generates the same code as C-style bitmask operations for smaller-sized sets.
Since the C++ standard library has provided these appropriate containers for about a generation, perhaps the book include the bitvector class as exposition?