Namespaces
Variants

std::vector<bool>

From cppreference.com
Revision as of 13:44, 8 January 2013 by Oli (talk | contribs) (Notes: does not fulfill one container requirement (ForwardIterator) because of proxy reference use)
 
 
 
 
Defined in header <vector>
template<class Allocator = std::allocator<bool>> 
class vector<bool, Allocator>;

std::vector<bool> is a space-efficient specialization of std::vector for the type bool.

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.

std::vector<bool> behaves similarly to std::vector, but in order to be space efficient, it:

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

Member types