Top of document
©Copyright 1999 Rogue Wave Software

Boolean Vectors

Vectors of bit values (boolean 1/0 values) are handled as a special case by the standard library, so that the values can be efficiently packed (several elements to a word). The operations for a boolean vector , vector<bool>, are a superset of those for an ordinary vector, only the implementation is more efficient.

One new member function added to the boolean vector data type is flip(). When invoked, this function inverts all the bits of the vector. Boolean vectors also return as reference an internal value that also supports the flip() member function.

   vector<bool> bvec(27);
    bvec.flip();               // flip all values
    bvec[17].flip();           // flip bit 17

vector<bool> also supports an additional swap() member function that allows you to swap the values indicated by a pair of references.

   bvec.swap(bvec [17], bvec [16]);

Top of document