#pragma once #include "memory.hpp" #include "utils.hpp" #include #include template memType *malloc_s(unsigned int size) { auto *mem = malloc(size); if (mem == nullptr) { Serial.println("Error: Memory allocation failed"); while (true) {} } return static_cast(mem); } template UniquePtr::UniquePtr(Target *target) : _target(target) { } template UniquePtr::UniquePtr(const UniquePtr &unique_ptr) : _target(new Target(*(unique_ptr._target))) { } template UniquePtr::UniquePtr(UniquePtr &&unique_ptr) noexcept : _target(unique_ptr._target) { unique_ptr._target = nullptr; } template UniquePtr &UniquePtr::operator=(const UniquePtr &unique_ptr) { if (&unique_ptr != this) { delete _target; _target = nullptr; _target = new Target(*(unique_ptr._target)); } return *this; } template UniquePtr &UniquePtr::operator=(UniquePtr &&unique_ptr) noexcept { if (&unique_ptr != this) { delete _target; _target = unique_ptr._target; unique_ptr._target = nullptr; } return *this; } template UniquePtr::~UniquePtr() { if (this->_target != nullptr) { delete this->_target; } } template Target UniquePtr::operator*() const { return *(this->_target); } template Target *UniquePtr::operator->() const { return this->_target; } template UniquePtr make_unique(Args... args) { return UniquePtr(new Target(args...)); }