This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help on Biset


Would this work until the functionality is established in the sgi
headers?

#include <iostream>
#include <bitset>

using namespace std;

template <size_t _Nb, class _WordT>
string &operator << (string &_s, bitset <_Nb, _WordT> _b)
{
  _s.assign(_Nb, '0');
  
  for (size_t i = 0; i < _Nb; ++i) 
    if (_b.test(i)) _s[_Nb - 1 - i] = '1';
  
  return _s;
}

template <size_t _Nb, class _WordT>
ostream &operator << (ostream &_s, bitset <_Nb, _WordT> _b)
{
  string s;
  s << _b;
  
  _s << s;
  return _s;
}

int
main(void)
{
    bitset <12> b( 96 );
    
    string s;
    s << b;
    
    cerr << s << " " << b << endl;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]