#pragma once template class Array { T* arr; unsigned size; unsigned allocated; void resize(); void free(); void copyFrom(const Array& other); public: Array(); ~Array(); Array(const Array& other); Array& operator=(const Array& other); Array(Array&& other); Array& operator=(Array&& other); T& operator[](unsigned index); T& operator[](unsigned index) const; Array& operator+=(const Array& right); template friend bool operator==(const Array& left, const Array& right); template friend bool operator!=(const Array& left, const Array& right); template friend Array operator+(const Array& left, const Array& right); }; template void Array::resize() { allocated *= 2; T* biggerArr = new T[allocated]; for (int i = 0; i < size; i++) { biggerArr[i] = arr[i]; } delete[] arr; arr = biggerArr; } template void Array::free() { delete[] arr; } template void Array::copyFrom(const Array& other) { this->size = other.size; this->allocated = other.allocated; this->arr = new T[allocated]; for (int i = 0; i < size; i++) { this->arr[i] = other.arr[i]; } } template Array::Array() { this->arr = nullptr; allocated = size = 0; } template Array::~Array() { free(); } template Array::Array(const Array& other) { copyFrom(other); } template Array& Array::operator=(const Array& other) { if (this != &other) { free(); copyFrom(other); } return *this; } template Array::Array(Array&& other) { this->arr = other.arr; other.arr = nullptr; } template Array& Array::operator=(Array&& other) { if (this != &other) { free(); this->arr = other.arr; other.arr = nullptr; } return *this; } template T& Array::operator[](unsigned index) { return arr[index]; } template T& Array::operator[](unsigned index) const { return arr[index]; } template Array& Array::operator+=(const Array& right) { for (int i = 0; i < right.size; i++) { if (size == allocated) { resize(); } arr[size++] = right[i]; } } template bool operator==(const Array& left, const Array& right) { if (left.size != right.size) { return false; } for (int i = 0; i < left.size; i++) { if (left.arr[i] != right.arr[i]) { return false; } } return true; } template bool operator!=(const Array& left, const Array& right) { return !(left == right); } template Array operator+(const Array& left, const Array& right) { Array concat; concat += left; concat += right; return concat; }