//This file is part of the IVD project and is licensed under the terms of the LGPL-3.0-only #pragma once #include namespace RustUtils { //I know it's frowned upon to inherit from std classes but fucking byte me. //This is just for the trivial case where I want a deep copy and nothing fancy. template class DeepCopyableUnique : public std::unique_ptr { public: typedef std::unique_ptr Parent; DeepCopyableUnique() noexcept {} DeepCopyableUnique(const DeepCopyableUnique& other) noexcept: Parent(other.get() ? std::make_unique(*other.get()) : nullptr) {} DeepCopyableUnique(const Parent&& other) noexcept: Parent(other) {} DeepCopyableUnique& operator=(const DeepCopyableUnique& other) noexcept { if(other.get()) Parent::operator=(std::make_unique(*other.get())); else Parent::reset(); return *this; } DeepCopyableUnique& makeCopy(const T& other) { Parent::operator=(std::make_unique(other)); return *this; } }; }//RustUtils