Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/vector bool"

From cppreference.com
< cpp‎ | container
(The actual optimization is implementation-defined)
(wording)
Line 6: Line 6:
 
}}  
 
}}  
  
{{c|std::vector<bool>}} is a space-efficient specialization of {{c|std::vector}} for the type {{c|bool}}. The efficiency can be potentially achieved by coalescing the elements in such a way, that each of them occupies only one bit, as opposed to at least one byte, which is the size of {{c|bool}}. The actual optimization and whether {{c|std::vector<bool>}} is optimized at all is implementation-defined.
+
{{c|std::vector<bool>}} is a space-efficient specialization of {{c|std::vector}} for the type {{c|bool}}.  
 +
 
 +
The manner in which {{c|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 {{c|bool}}.
  
 
{{c|std::vector<bool>}} behaves similarly to {{c|std::vector}}, but in order to be space efficient, it:
 
{{c|std::vector<bool>}} behaves similarly to {{c|std::vector}}, but in order to be space efficient, it:

Revision as of 15:12, 3 October 2012

 
 
 
 
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.

Contents

Member types

Template:cpp/container/dcl list value typeTemplate:cpp/container/dcl list allocator typeTemplate:cpp/container/dcl list size typeTemplate:cpp/container/dcl list difference typeTemplate:cpp/container/dcl list const referenceTemplate:cpp/container/dcl list pointerTemplate:cpp/container/dcl list const pointerTemplate:cpp/container/dcl list iteratorTemplate:cpp/container/dcl list const iteratorTemplate:cpp/container/dcl list reverse iteratorTemplate:cpp/container/dcl list const reverse iterator
Member type Definition
proxy class representing a reference to a single bool
(class)

Member functions

Template:cpp/container/dcl list constructorTemplate:cpp/container/dcl list destructorTemplate:cpp/container/dcl list operator=Template:cpp/container/dcl list assignTemplate:cpp/container/dcl list get allocatorTemplate:cpp/container/dcl list atTemplate:cpp/container/dcl list operator atTemplate:cpp/container/dcl list frontTemplate:cpp/container/dcl list backTemplate:cpp/container/dcl list beginTemplate:cpp/container/dcl list endTemplate:cpp/container/dcl list rbeginTemplate:cpp/container/dcl list rendTemplate:cpp/container/dcl list emptyTemplate:cpp/container/dcl list sizeTemplate:cpp/container/dcl list max sizeTemplate:cpp/container/dcl list reserveTemplate:cpp/container/dcl list capacityTemplate:cpp/container/dcl list clearTemplate:cpp/container/dcl list insertTemplate:cpp/container/dcl list eraseTemplate:cpp/container/dcl list push backTemplate:cpp/container/dcl list pop backTemplate:cpp/container/dcl list resizeTemplate:cpp/container/dcl list swapTemplate:cpp/container/vector bool/dcl list flipTemplate:cpp/container/vector bool/dcl list swap
Element access
Iterators
Capacity
Modifiers
vector<bool> specific modifiers

Non-member functions

Template:cpp/container/dcl list operator cmpTemplate:cpp/container/dcl list swap2

Notes

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 std::vector<bool>.