const_reference

class const_reference;

The nested class const_reference is a "smart reference" class which emulates a const reference to an internal bool. An actual reference ( const bool&) can not be used here since the internal bools are stored as a single bit. In most cases the behavior will be identical to const bool&. As it applies to std::vector<bool>::const_reference, this is an extension to the standard. The standard specifies that std::vector<bool>::const_reference is just a bool. But the following code demonstrates how this proxy class more closely emulates a const bool& than does a bool. Another extension to better emulate a real const reference is that you can take the address of a const_reference which yields the nested type const_pointer.

  #include <bitvector>
  #include <cassert>

  int main()
  {
      Metrowerks::bitvector<> v(3);
      Metrowerks::bitvector<>::const_reference cr = v[0];
      assert(cr == false);
      v[0] = true;
      assert(cr == true);
      Metrowerks::bitvector<>::const_pointer cp = &cr;
      assert(*cp == true);
  }