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
498  { // return bitset _Left AND _Right
499  bitset<_Bits> _Ans = _Left;
500  return (_Ans &= _Right);
501  }
constexpr const _Ty &() _Left
Definition: algorithm:3722
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
524  { // insert bitset as a string
525  const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>);
526  const _Elem _E0 = _Ctype_fac.widen('0');
527  const _Elem _E1 = _Ctype_fac.widen('1');
528 
529  return (_Ostr
530  << _Right.template to_string<_Elem, _Tr, allocator<_Elem> >(
531  _E0, _E1));
532  }
#define _USE(loc, fac)
Definition: xlocale:499
Definition: iosfwd:558
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:432
string to_string(int _Val)
Definition: string:532
Definition: xlocale:2077
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2126
template<class _Elem , class _Tr , size_t _Bits>
basic_istream<_Elem, _Tr>& operator>> ( basic_istream< _Elem, _Tr > &  _Istr,
bitset< _Bits > &  _Right 
)
inline
540  { // extract bitset as a string
541  const ctype<_Elem>& _Ctype_fac = _USE(_Istr.getloc(), ctype<_Elem>);
542  const _Elem _E0 = _Ctype_fac.widen('0');
543  const _Elem _E1 = _Ctype_fac.widen('1');
544  ios_base::iostate _State = ios_base::goodbit;
545  bool _Changed = false;
546  string _Str;
547  const typename basic_istream<_Elem, _Tr>::sentry _Ok(_Istr);
548 
549  if (_Ok)
550  { // valid stream, extract elements
552  typename _Tr::int_type _Meta = _Istr.rdbuf()->sgetc();
553  for (size_t _Count = _Right.size(); 0 < _Count;
554  _Meta = _Istr.rdbuf()->snextc(), --_Count)
555  { // test _Meta
556  _Elem _Char;
557  if (_Tr::eq_int_type(_Tr::eof(), _Meta))
558  { // end of file, quit
559  _State |= ios_base::eofbit;
560  break;
561  }
562  else if ((_Char = _Tr::to_char_type(_Meta)) != _E0
563  && _Char != _E1)
564  break; // invalid element
565  else if (_Str.max_size() <= _Str.size())
566  { // no room in string, give up (unlikely)
567  _State |= ios_base::failbit;
568  break;
569  }
570  else
571  { // valid, append '0' or '1'
572  if (_Char == _E1)
573  _Str.append(1, '1');
574  else
575  _Str.append(1, '0');
576  _Changed = true;
577  }
578  }
579  _CATCH_IO_(_Istr)
580  }
581 
582  if (!_Changed)
583  _State |= ios_base::failbit;
584  _Istr.setstate(_State);
585  _Right = bitset<_Bits>(_Str); // convert string and store
586  return (_Istr);
587  }
int_type __CLR_OR_THIS_CALL sgetc()
Definition: streambuf:153
static constexpr _Iostate failbit
Definition: xiosbase:88
#define _CATCH_IO_(x)
Definition: ostream:31
Definition: istream:110
constexpr size_t size() const _NOEXCEPT
Definition: bitset:382
#define _USE(loc, fac)
Definition: xlocale:499
#define _TRY_IO_BEGIN
Definition: ostream:29
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:432
_Mysb *__CLR_OR_THIS_CALL rdbuf() const
Definition: ios:89
_Myt & append(initializer_list< _Elem > _Ilist)
Definition: xstring:2199
Definition: xlocale:2077
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
int_type __CLR_OR_THIS_CALL snextc()
Definition: streambuf:165
size_type max_size() const _NOEXCEPT
Definition: xstring:3028
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2126
Definition: bitset:21
static constexpr _Iostate goodbit
Definition: xiosbase:86
size_type size() const _NOEXCEPT
Definition: xstring:3023
_Diff _Count
Definition: algorithm:1941
static constexpr _Iostate eofbit
Definition: xiosbase:87
void __CLR_OR_THIS_CALL setstate(iostate _State, bool _Reraise=false)
Definition: ios:55
template<size_t _Bits>
bitset<_Bits> operator^ ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
514  { // return bitset _Left XOR _Right
515  bitset<_Bits> _Ans = _Left;
516  return (_Ans ^= _Right);
517  }
constexpr const _Ty &() _Left
Definition: algorithm:3722
Definition: bitset:21
template<size_t _Bits>
bitset<_Bits> operator| ( const bitset< _Bits > &  _Left,
const bitset< _Bits > &  _Right 
)
inline
506  { // return bitset _Left OR _Right
507  bitset<_Bits> _Ans = _Left;
508  return (_Ans |= _Right);
509  }
constexpr const _Ty &() _Left
Definition: algorithm:3722
Definition: bitset:21