T* m_p;
size_t m_index;
public:
+ class _bit
+ {
+ protected:
+ bit_ptr& parent;
+ public:
+ _bit(bit_ptr& in) : parent(in) {}
+
+ _bit operator = (bool b){ parent.set(b); return *this; }
+ operator bool(){ return parent.get(); }
+ operator char(){ return parent.get(); }
+ operator unsigned char(){ return parent.get(); }
+ operator short(){ return parent.get(); }
+ operator unsigned short(){ return parent.get(); }
+ operator int(){ return parent.get(); }
+ operator unsigned int(){ return parent.get(); }
+ operator long(){ return parent.get(); }
+ operator unsigned long(){ return parent.get(); }
+ };
+
+ public:
bit_ptr(T* p, size_t index=0) : m_p(p), m_index(index) {}
bit_ptr& operator ++(int){ m_index++; return *this; }
bit_ptr& operator -=(int n){ m_index-=n; return *this; }
bit_ptr& operator +(int n){ bit_ptr work=*this; work+=n; return work; }
bit_ptr& operator -(int n){ bit_ptr work=*this; work-=n; return work; }
+
+ _bit operator *(){ return _bit(*this); }
+
+ void set(bool b)
+ {
+ size_t ary_index = m_index / TypeBits;
+ size_t bit_index = m_index % TypeBits;
+ m_p[ary_index] |= (b << bit_index);
+ }
+ bool get()
+ {
+ size_t ary_index = m_index / TypeBits;
+ size_t bit_index = m_index % TypeBits;
+ return m_p[ary_index] & (1 << bit_index);
+ }
};
//template <unsigned int _BitCount, typename _BaseType = unsigned int>