SGI

bit_vector

Category: containers Component type: type

Description

A bit_vector is essentially a vector<bool>: it is a Sequence that has the same interface as vector. The main difference is that bit_vector is optimized for space efficiency. A vector always requires at least one byte per element, but a bit_vector only requires one bit per element.

Warning: The name bit_vector will be removed in a future release of the STL. The only reason that bit_vector is a separate class, instead of a template specialization of vector<bool>, is that this would require partial specialization of templates. On compilers that support partial specialization, bit_vector is a specialization of vector<bool>. The name bit_vector is a typedef. This typedef is not defined in the C++ standard, and is retained only for backward compatibility.

Example

bit_vector V(5);
V[0] = true;
V[1] = false;
V[2] = false;
V[3] = true;
V[4] = false;

for (bit_vector::iterator i = V.begin(); i < V.end(); ++i)
  cout << (*i ? '1' : '0');
cout << endl;

Definition

Defined in the standard header vector, and in the nonstandard backward-compatibility header bvector.h.

Template parameters

None. Bit_vector is not a class template.

Model of

Random access container, Back insertion sequence.

Type requirements

None.

Public base classes

None.

Members

Member Where defined Description
value_type Container The type of object stored in the bit_vector: bool
reference bit_vector A proxy class that acts as a reference to a single bit. See below for details.
const_reference Container Const reference to value_type. In bit_vector this is simply defined to be bool.
size_type Container An unsigned integral type.
difference_type Container A signed integral type.
iterator Container Iterator used to iterate through a bit_vector.
const_iterator Container Const iterator used to iterate through a bit_vector.
reverse_iterator Reversible Container Iterator used to iterate backwards through a bit_vector.
const_reverse_iterator Reversible Container Const iterator used to iterate backwards through a bit_vector.
iterator begin() Container Returns an iterator pointing to the beginning of the bit_vector.
iterator end() Container Returns an iterator pointing to the end of the bit_vector.
const_iterator begin() const Container Returns a const_iterator pointing to the beginning of