#include <iostream>
#include <vector>
#include <cstddef>

class bitArray
{
private:
   std::vector<int> sortie;
public:
   explicit bitArray(int size): sortie(size) {}
   bitArray& operator+=(const std::size_t i)
   {
      if (0 <= i && i < sortie.size()) // check for (0 <= index < size) of the array
      {
            this ->sortie[i] = 1;
            return *this;
      }
      else
      {
         // do your logic;
         // for instance, I have done something like follows:
         std::cout << "out of bound" << std::endl;
         if(sortie.size() == 0) // if the size of array == 0
            sortie.resize(1,0);
      }
      return *this;
   }
   int operator[] (const std::size_t index)
   {
      return (0 <= index && index < sortie.size()) ?  // check for (0 <= index < size) of the array
               sortie[index] : -1;
   }
};
int main ()
{
   bitArray obj(3);
   obj += 2;
   std::cout << obj[2] << std::endl;

   obj += -2;
   std::cout << obj[-2] << std::endl;

   obj += 22;
   std::cout << obj[22] << std::endl;

   return 0;
}
