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
496  { // return bitset _Left AND _Right
497  bitset<_Bits> _Ans = _Left;
498  return (_Ans &= _Right);
499  }
constexpr const _Ty &() _Left
Definition: algorithm:3590
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
522  { // insert bitset as a string
523  const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>);
524  const _Elem _E0 = _Ctype_fac.widen('0');
525  const _Elem _E1 = _Ctype_fac.widen('1');
526 
527  return (_Ostr
528  << _Right.template to_string<_Elem, _Tr, allocator<_Elem> >(
529  _E0, _E1));
530  }
#define _USE(loc, fac)
Definition: xlocale:547
Definition: iosfwd:612
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:433
string to_string(int _Val)
Definition: string:574
Definition: xlocale:2115
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2164
template<class _Elem , class _Tr , size_t _Bits>
basic_istream<_Elem, _Tr>& operator>> ( basic_istream< _Elem, _Tr > &  _Istr,
bitset< _Bits > &  _Right 
)
inline
538  { // extract bitset as a string
539  const ctype<_Elem>& _Ctype_fac = _USE(_Istr.getloc(), ctype<_Elem>);
540  const _Elem _E0 = _Ctype_fac.widen('0');
541  const _Elem _E1 = _Ctype_fac.widen('1');
542  ios_base::iostate _State = ios_base::goodbit;
543  bool _Changed = false;
544  string _Str;
545  const typename basic_istream<_Elem, _Tr>::sentry _Ok(_Istr);
546 
547  if (_Ok)
548  { // valid stream, extract elements
550  typename _Tr::int_type _Meta = _Istr.rdbuf()->sgetc();
551  for (size_t _Count = _Right.size(); 0 < _Count;
552  _Meta = _Istr.rdbuf()->snextc(), --_Count)
553  { // test _Meta
554  _Elem _Char;
555  if (_Tr::eq_int_type(_Tr::eof(), _Meta))
556  { // end of file, quit
557  _State |= ios_base::eofbit;
558  break;
559  }
560  else if ((_Char = _Tr::to_char_type(_Meta)) != _E0
561  && _Char != _E1)
562  break; // invalid element
563  else if (_Str.max_size() <= _Str.size())
564  { // no room in string, give up (unlikely)
565  _State |= ios_base::failbit;
566  break;
567  }
568  else
569  { // valid, append '0' or '1'
570  if (_Char == _E1)
571  _Str.append(1, '1');
572  else
573  _Str.append(1, '0');
574  _Changed = true;
575  }
576  }
577  _CATCH_IO_(_Istr)
578  }
579 
580  if (!_Changed)
581  _State |= ios_base::failbit;
582  _Istr.setstate(_State);
583  _Right = bitset<_Bits>(_Str); // convert string and store
584  return (_Istr);
585  }
int_type __CLR_OR_THIS_CALL sgetc()
Definition: streambuf:154
static constexpr _Iostate failbit
Definition: xiosbase:89
#define _CATCH_IO_(x)
Definition: ostream:32
Definition: istream:111
unsigned int _Count
Definition: xcomplex:668
constexpr size_t size() const _NOEXCEPT
Definition: bitset:380
#define _USE(loc, fac)
Definition: xlocale:547
#define _TRY_IO_BEGIN
Definition: ostream:30
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:433
_Mysb *__CLR_OR_THIS_CALL rdbuf() const
Definition: ios:90
Definition: xlocale:2115
int_type __CLR_OR_THIS_CALL snextc()
Definition: streambuf:166
size_type max_size() const _NOEXCEPT
Definition: xstring:1768
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2164
Definition: bitset:21
static constexpr _Iostate goodbit
Definition: xiosbase:87
size_type size() const _NOEXCEPT
Definition: xstring:1763
_Myt & append(_XSTD initializer_list< _Elem > _Ilist)
Definition: xstring:998
static constexpr _Iostate eofbit
Definition: xiosbase:88
void __CLR_OR_THIS_CALL setstate(iostate _State, bool _Reraise=false)
Definition: ios:56
template<size_t _Bits>
bitset<_Bits> operator^ ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
512  { // return bitset _Left XOR _Right
513  bitset<_Bits> _Ans = _Left;
514  return (_Ans ^= _Right);
515  }
constexpr const _Ty &() _Left
Definition: algorithm:3590
Definition: bitset:21
template<size_t _Bits>
bitset<_Bits> operator| ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
504  { // return bitset _Left OR _Right
505  bitset<_Bits> _Ans = _Left;
506  return (_Ans |= _Right);
507  }
constexpr const _Ty &() _Left
Definition: algorithm:3590
Definition: bitset:21