reference

class reference;

The nested class reference is a "smart reference" class which emulates a reference to an internal bool. An actual reference ( 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 bool&. One exception is that the reference has a member function named flip() that will change the value of the underlying bit.

  #include <bitvector>
  #include <algorithm>
  #include <cassert>

  int main()
  {
      Metrowerks::bitvector<> v(3);
      Metrowerks::bitvector<>::reference r = v[0];

      assert(v[0] == false);
      assert(r == false);
      r = true;

      assert(v[0] == true);
      r.flip();

      assert(v[0] == false);
      v[1] = true;
      swap(r, v[1]);

      assert(r == true);
      assert(v[0] == true);
      assert(v[1] == false);

      Metrowerks::bitvector<>::pointer p = &r;

      assert(*p == true);
      *p = false;

      assert(v[0] == false);
      assert(r == false);
      assert(*p == false);
  }  
Note: swap can be called with this reference type, even with an rvalue reference. As it applies to std::vector<bool>::reference, this is an extension to the standard. Another extension to better emulate a real reference is that you can take the address of a reference that yields the nested type pointer.