#include <iostream> 
#include <vector> 
using namespace std;

enum class type {
  vector_type,
  integer_type
};

// Object can either be an Integer or Vector<Object> 
class Object {
public:
  type type_;
  union U {
    vector<Object> vec_;
    int num_;

    U() {}

    U(const vector<int> &vec) : vec_() {
      for (size_t i = 0; i < vec.size(); i++) {
        vec_.push_back(Object(i));
      }
    }

    U(int num) : num_(num) {}

    U& operator=(const vector<Object>& vec) {
      new(&vec_) vector<Object>(vec);
      return *this;
    }

    ~U() {}
  }u_;

  Object()
    : type_(type::integer_type)
  {
  }

  Object(const Object& other)
    : type_(other.type_)
  {
    if(other.type_ == type::vector_type)
      u_ = other.u_.vec_;
    else
      u_.num_ = other.u_.num_;
  }

  Object(const vector<int> &vec)
    : type_(type::vector_type),
      u_(vec)
  {
  }

  Object(int num)
    : type_(type::integer_type),
      u_(num)
  {
  }

  Object& operator=(const Object &other)
  {
    // Free old vector
    if(type_ == type::vector_type)
      u_.vec_.~vector();

    type_ = other.type_;
    if(other.type_ == type::vector_type)
      u_ = other.u_.vec_;
    else
      u_.num_ = other.u_.num_;
    return *this;
  }

  ~Object() {
    if(type_ == type::vector_type)
      u_.vec_.~vector();
  }
};

int main() {
  // to construct somth like that: [1,2, [3, [4,5], 6], 7] 
  Object o(vector<int>({ 1,2 }));

  return 0;
}