home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_09 / allison / bitstr.cpp < prev    next >
Encoding:
Text File  |  1994-07-10  |  536 b   |  31 lines

  1. // bitstr.cpp
  2.  
  3. // The following are added to the implementation of bitstring.
  4. // (See "Bit Manipulation in C++, Part 1", CUJ, Dec. 1993)
  5.  
  6. bitstring::bitref bitstring::operator[](size_t pos)
  7. {
  8.     return bitref(*this,pos);
  9. }
  10.  
  11. bitstring::bitref::bitref(bitstring& bs_, size_t bit_)
  12.   : bs(bs_)
  13. {
  14.     bit = bit_;
  15. }
  16.  
  17. int bitstring::bitref::operator=(int val)
  18. {
  19.     if (val)
  20.         bs.set(bit);
  21.     else
  22.         bs.reset(bit);
  23.     return val;
  24. }
  25.  
  26. bitstring::bitref::operator int()
  27. {
  28.     return bs.test(bit);
  29. }
  30.  
  31.