STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Macros | Functions
bitset File Reference
#include <string>
#include <iosfwd>

Classes

class  bitset< _Bits >
 
struct  hash< bitset< _Bits > >
 

Macros

#define _BITSET_
 
#define _BITSET_SIZE_TYPE   typename basic_string<_Elem, _Tr, _Alloc>::size_type
 

Functions

template<size_t _Bits>
bitset< _Bits > operator& (const bitset< _Bits > &_Left, const bitset< _Bits > &_Right) _NOEXCEPT
 
template<size_t _Bits>
bitset< _Bits > operator| (const bitset< _Bits > &_Left, const bitset< _Bits > &_Right) _NOEXCEPT
 
template<size_t _Bits>
bitset< _Bits > operator^ (const bitset< _Bits > &_Left, const bitset< _Bits > &_Right) _NOEXCEPT
 
template<class _Elem , class _Tr , size_t _Bits>
basic_ostream< _Elem, _Tr > & operator<< (basic_ostream< _Elem, _Tr > &_Ostr, const bitset< _Bits > &_Right)
 
template<class _Elem , class _Tr , size_t _Bits>
basic_istream< _Elem, _Tr > & operator>> (basic_istream< _Elem, _Tr > &_Istr, bitset< _Bits > &_Right)
 

Macro Definition Documentation

#define _BITSET_
#define _BITSET_SIZE_TYPE   typename basic_string<_Elem, _Tr, _Alloc>::size_type

Function Documentation

template<size_t _Bits>
bitset<_Bits> operator& ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
504  { // return bitset _Left AND _Right
505  bitset<_Bits> _Ans = _Left;
506  return (_Ans &= _Right);
507  }
Definition: bitset:21
template<class _Elem , class _Tr , size_t _Bits>
basic_ostream<_Elem, _Tr>& operator<< ( basic_ostream< _Elem, _Tr > &  _Ostr,
const bitset< _Bits > &  _Right 
)
inline
530  { // insert bitset as a string
531  const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>);
532  const _Elem _E0 = _Ctype_fac.widen('0');
533  const _Elem _E1 = _Ctype_fac.widen('1');
534 
535  return (_Ostr
536  << _Right.template to_string<_Elem, _Tr, allocator<_Elem> >(
537  _E0, _E1));
538  }
#define _USE(loc, fac)
Definition: xlocale:555
Definition: iosfwd:611
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:422
string to_string(int _Val)
Definition: string:500
Definition: xlocale:2113
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2162
template<class _Elem , class _Tr , size_t _Bits>
basic_istream<_Elem, _Tr>& operator>> ( basic_istream< _Elem, _Tr > &  _Istr,
bitset< _Bits > &  _Right 
)
inline
546  { // extract bitset as a string
547  const ctype<_Elem>& _Ctype_fac = _USE(_Istr.getloc(), ctype<_Elem>);
548  const _Elem _E0 = _Ctype_fac.widen('0');
549  const _Elem _E1 = _Ctype_fac.widen('1');
550  ios_base::iostate _State = ios_base::goodbit;
551  bool _Changed = false;
552  string _Str;
553  const typename basic_istream<_Elem, _Tr>::sentry _Ok(_Istr);
554 
555  if (_Ok)
556  { // valid stream, extract elements
558  typename _Tr::int_type _Meta = _Istr.rdbuf()->sgetc();
559  for (size_t _Count = _Right.size(); 0 < _Count;
560  _Meta = _Istr.rdbuf()->snextc(), --_Count)
561  { // test _Meta
562  _Elem _Char;
563  if (_Tr::eq_int_type(_Tr::eof(), _Meta))
564  { // end of file, quit
565  _State |= ios_base::eofbit;
566  break;
567  }
568  else if ((_Char = _Tr::to_char_type(_Meta)) != _E0
569  && _Char != _E1)
570  break; // invalid element
571  else if (_Str.max_size() <= _Str.size())
572  { // no room in string, give up (unlikely)
573  _State |= ios_base::failbit;
574  break;
575  }
576  else
577  { // valid, append '0' or '1'
578  if (_Char == _E1)
579  _Str.append(1, '1');
580  else
581  _Str.append(1, '0');
582  _Changed = true;
583  }
584  }
585  _CATCH_IO_(_Istr)
586  }
587 
588  if (!_Changed)
589  _State |= ios_base::failbit;
590  _Istr.setstate(_State);
591  _Right = bitset<_Bits>(_Str); // convert string and store
592  return (_Istr);
593  }
int_type __CLR_OR_THIS_CALL sgetc()
Definition: streambuf:150
static const _Iostate failbit
Definition: xiosbase:89
#define _CATCH_IO_(x)
Definition: ostream:32
Definition: istream:111
#define _USE(loc, fac)
Definition: xlocale:555
#define _TRY_IO_BEGIN
Definition: ostream:30
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:422
_Mysb *__CLR_OR_THIS_CALL rdbuf() const
Definition: ios:86
Definition: xlocale:2113
int_type __CLR_OR_THIS_CALL snextc()
Definition: streambuf:162
size_type max_size() const _NOEXCEPT
Definition: xstring:1757
size_t size() const _NOEXCEPT
Definition: bitset:387
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2162
Definition: bitset:21
static const _Iostate goodbit
Definition: xiosbase:87
size_type size() const _NOEXCEPT
Definition: xstring:1752
_Diff _Count
Definition: algorithm:1941
_Myt & append(_XSTD initializer_list< _Elem > _Ilist)
Definition: xstring:972
static const _Iostate eofbit
Definition: xiosbase:88
void __CLR_OR_THIS_CALL setstate(iostate _State, bool _Reraise=false)
Definition: ios:54
template<size_t _Bits>
bitset<_Bits> operator^ ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
520  { // return bitset _Left XOR _Right
521  bitset<_Bits> _Ans = _Left;
522  return (_Ans ^= _Right);
523  }
Definition: bitset:21
template<size_t _Bits>
bitset<_Bits> operator| ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
512  { // return bitset _Left OR _Right
513  bitset<_Bits> _Ans = _Left;
514  return (_Ans |= _Right);
515  }
Definition: bitset:21