Defined in header
template<class Allocator = std::allocator<bool>>
class vector<bool, Allocator>;
The manner in which std::vector<bool> is made space efficient (as well as whether it is optimized at all) is implementation defined. One potential optimization involves coalescing vector elements such that each element occupies a single bit instead of a byte-sized bool.
- Does not necessarily store its data in a single contiguous chunk of memory.
- Exposes std::vector<bool>::reference as a method of accessing individual bits.
- Does not use std::allocator_traits::construct to construct bit values.
If the size of the bitset is known at compile time, std::bitset may be used, which offers a richer set of member functions. In addition, boost::dynamic_bitset exists as an alternative to
Since its representation may by optimized, std::vector<bool> does not necessarily meet all
SequenceContainer requirements. For example, because std::vector<bool>::iterator is implementation-defined, it may not satisfy the
ForwardIterator requirement. Use of algorithms such as std::search that require
ForwardIterators may result in either compile-time or run-time errors.