Top of document
©Copyright 1999 Rogue Wave Software

bitset


     Container

Summary

A template class and related functions for storing and manipulating fixed-size sequences of bits.

Contents

Synopsis

#include <bitset>
template <size_t N>
class bitset ;

Description

bitset<size_t N> is a class that describes objects that can store a sequence consisting of a fixed number of bits, N. Each bit represents either the value zero (reset) or one (set) and has a non-negative position pos.

Errors and exceptions

Bitset constructors and member functions may report the following three types of errors -- each associated with a distinct exception:

If exceptions are not supported on your compiler, you will get an assertion failure instead of an exception.

Interface

template <size_t N>
class bitset {
public:
// bit reference:
  class reference {
   friend class bitset<N>;
  public:
   ~reference();
   reference& operator= (bool);
   reference& operator= (const reference&);
   bool operator~() const;
   operator bool() const;
   reference& flip();
  };
// Constructors  bitset ();
  bitset (unsigned long);
  explicit bitset (const string&, size_t = 0,
                   size_t = (size_t)-1);
  bitset (const bitset<N>&);
  bitset<N>& operator= (const bitset<N>&); 
// Bitwise Operators and Bitwise Operator Assignment   bitset<N>& operator&= (const bitset<N>&);
   bitset<N>& operator|= (const bitset<N>&);
   bitset<N>& operator^= (const bitset<N>&);
   bitset<N>& operator<<= (size_t);
   bitset<N>& operator>>= (size_t);
// Set, Reset, Flip bitset<N>& set ();
   bitset<N>& set (size_t, int = 1);
   bitset<N>& reset ();
   bitset<N>& reset (size_t);
   bitset<N> operator~() const;
   bitset<N>& flip ();
   bitset<N>& flip (size_t);
// element access
   reference operator[] (size_t);
   unsigned long to_ulong() const;
   string to_string() const;
   size_t count() const;
   size_t size() const;
   bool operator== (const bitset<N>&) const;
   bool operator!= (const bitset<N>&) const;
   bool test (size_t) const;
   bool any() const;
   bool none() const;
   bitset<N> operator<< (size_t) const;
   bitset<N> operator>> (size_t) const;
};
// Non-member operators template <size_t N>
bitset<N> operator& (const bitset<N>&, const bitset<N>&);
template <size_t N>
bitset<N> operator| (const bitset<N>&, const bitset<N>&);
template <size_t N>
bitset<N> operator^ (const bitset<N>&, const bitset<N>&);
template <size_t N>
istream& operator>> (istream&, bitset<N>&);
template <size_t N>
ostream& operator<< (ostream&, const bitset<N>&);

Constructors

bitset();
bitset(unsigned long val);
explicit  
bitset (const string& str, size_t pos = 0,
        size_t n = (size_t)-1);
bitset(const bitset<N>& rhs);

Assignment Operator

bitset<N>& operator= (const bitset<N>& rhs);

Operators

bool 
operator== (const bitset<N>& rhs) const;
bool 
operator!= (const bitset<N>& rhs) const;
bitset<N>& 
operator&= (const bitset<N>& rhs);
bitset<N>& 
operator|= (const bitset<N>& rhs);
bitset<N>&
operator^= (const bitset<N>& rhs);
bitset<N>& 
operator<<= (size_t pos);
bitset<N>& 
operator>>= (size_t pos);
bitset<N>&
operator>> (size_t pos) const;
bitset<N>& 
operator<< (size_t pos) const;
bitset<N> 
operator~ () const;
bitset<N> 
operator& (const bitset<N>& lhs,
           const bitset<N>& rhs);
bitset<N> 
operator| (const bitset<N>& lhs,
           const bitset<N>& rhs);
bitset<N> 
operator^ (const bitset<N>& lhs,
           const bitset<N>& rhs);
template <size_t N>
istream& 
operator>> (istream& is, bitset<N>& x);
template <size_t N>
ostream& 
operator<< (ostream& os, const bitset<N>& x);

Member Functions

bool 
any () const;
size_t 
count () const;
bitset<N>& 
flip();
bitset<N>& 
flip (size_t pos);
bool 
none () const;
bitset<N>& 
reset();
bitset<N>& 
reset (size_t pos);
bitset<N>& 
set();
bitset<N>& 
set (size_t pos, int val = 1);
size_t 
size () const;
bool 
test (size_t pos) const;
string 
to_string() const;
unsigned long 
to_ulong() const;

See Also

Containers


Top of document