Name

bitset class template — Fixed-size sequence of bits

Synopsis

template<size_t N>
class bitset {
public:
  // Proxy class to simulate a bit reference
  class reference {
    friend class bitset;
    reference(  );
  public:
    ~reference(  );
    reference& operator=(bool x);
    reference& operator=(const reference&);
    bool operator~(  ) const;
    operator bool(  ) const;
    reference& flip(  );
  };

  // Constructors 
  bitset(  ); 
  bitset(unsigned long val);

  template<typename charT, typename traits, typename A>
  explicit bitset(const basic_string<charT,traits,A>& s, typename 
    basic_string<charT,traits,A>::size_type p=0, typename basic
    string<charT,traits,A>::size_type n = basic_string<charT,traits,A>::npos);

  // bitset operations
  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>& set(  );
  bitset<N>& set(size_t pos, int val=true);
  bitset<N>& reset(  );
  bitset<N>& reset(size_t pos);
  bitset<N>  operator~(  ) const;
  bitset<N>& flip(  );
  bitset<N>& flip(size_t pos);
  
  // Element access
  reference operator[](size_t pos);
  bool operator[](size_t pos) const;
  
  unsigned long  to_ulong(  ) const;
  template <typename charT, typename traits, typename Alloc>
    basic_string<charT, traits, Alloc> to_string(  ) const;
  
  size_t count(  ) const;
  size_t size(  )  const; 
  bool operator==(const bitset<N>& rhs) const;
  bool operator!=(const bitset<N>& rhs) const;
  bool test(size_t pos) const;
  bool any( ) ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.