Advertisement
apachee

Untitled

Apr 1st, 2022
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. template <class IntegralT = std::uint32_t>
  2. class BitSet {
  3. public:
  4.     BitSet();
  5.     BitSet(const int size, const bool v = false);
  6.  
  7.     class BitHolder {
  8.     public:
  9.         BitHolder& operator=(bool v);
  10.         operator bool() const;
  11.     private:
  12.         BitHolder(IntegralT *ptr, unsigned int pos);
  13.         friend class BitSet<IntegralT>;
  14.  
  15.         IntegralT *ptr{ nullptr };
  16.         unsigned int pos{ 0 };
  17.     };
  18.  
  19.     bool operator[](const int index) const;
  20.     BitHolder operator[](const int index);
  21.  
  22.     void resize(const int size);
  23.     int size() const;
  24.  
  25.     // bool operator==(const BitSet<T> &rhs) const;
  26.     // bool operator!=(const BitSet<T> &rhs) const;
  27.  
  28.     // BitSet<T>& operator<<=(const int shift);
  29.     // BitSet<T>& operator>>=(const int shift);
  30.     // BitSet<T>& operator&=(const BitSet<T> &rhs);
  31.     // BitSet<T>& operator|=(const BitSet<T> &rhs);
  32.     // BitSet<T>& operator^=(const BitSet<T> &rhs);
  33.  
  34.     // BitSet<T> operator~() const;
  35.  
  36.     // BitSet<T> operator<<(const int shift);
  37.     // BitSet<T> operator>>(const int shift);
  38.     // BitSet<T> operator&(const BitSet<T> &rhs);
  39.     // BitSet<T> operator|(const BitSet<T> &rhs);
  40.     // BitSet<T> operator^(const BitSet<T> &rhs);
  41.  
  42. private:
  43.     std::vector<IntegralT> data_{};
  44.     int size_{ 0 };
  45.  
  46.     static constexpr int integral_type_size_ = sizeof(IntegralT);
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement