#include <iostream>
#include <cstddef>

using namespace std;

struct proxy_obj;

struct my_bit_array
{

       uint8_t bit_array_;

       proxy_obj operator[](int n);
}
;

struct proxy_obj
{

       my_bit_array& my_bit_array_;
       int n_;

       proxy_obj(my_bit_array& bit_array, int n)
     : my_bit_array_(bit_array), n_(n) 
       {
       }


       proxy_obj& operator=(bool b)
     {

	        uint8_t set_mask = 0x01 << n_;

	        if(b) my_bit_array_.bit_array_ |= set_mask;
	        else  my_bit_array_.bit_array_ &= (~set_mask);

	        return *this;
     }


       operator bool()
     {
	 return my_bit_array_.bit_array_ & (0x01 << n_); 
     }

}
;

proxy_obj my_bit_array::operator[](int n)
{

       return proxy_obj(*this, n);
}


int main() 
{

       my_bit_array bit_set;

       bit_set[0] = false;
       bool b = bit_set[0];
       cout << b << endl;

       bit_set[3] = true;
       b = bit_set[3];
       cout << b << endl;

       return 0;
}
