Lecture overview -- Keyboard shortcut: 'u'  Previous page: Container member types -- Keyboard shortcut: 'p'  Next page: Algorithms [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 5 - Page 29 : 39
Notes about C++
Templates and The Standard Library
A vector specialization: vector<bool>

vector<bool> is a specialization of vector<T> that provides for compact representation of boolean vectors

vector<bool> complements the fixed-typed container bitset<N>

  • The C++ Programming Language: Page 548 - Vector<bool>. 492 - bitset<N>.
 

#include <iostream>
#include <vector>

int main(){
  using namespace std;

  vector<bool> vb;

  vb.push_back(true);  vb.push_back(true);  vb.push_back(false);
  vb.push_back(false); vb.push_back(false); vb.push_back(true);
  
  typedef vector<bool>::const_iterator VBI;

  for(VBI it = vb.begin(); it != vb.end(); it++) cout << *it;  // 110001
}

Illustration of the use of vector<bool>.