VERY experimental Nintendo Switch 2 emulator
C++
common: add make_unique_for_overwrite
ameerj80c173aba574
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txtindex 25b22a2815..f558f5a585 100644--- a/src/common/CMakeLists.txt+++ b/src/common/CMakeLists.txt@@ -78,6 +78,7 @@ add_library(common STATIClogging/types.hlz4_compression.cpplz4_compression.h+ make_unique_for_overwrite.hmath_util.hmemory_detect.cppmemory_detect.hdiff --git a/src/common/make_unique_for_overwrite.h b/src/common/make_unique_for_overwrite.hnew file mode 100644index 0000000000..c7413cf510--- /dev/null+++ b/src/common/make_unique_for_overwrite.h@@ -0,0 +1,25 @@+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#pragma once++#include <memory>+#include <type_traits>++namespace Common {++template <class T>+requires(!std::is_array_v<T>) std::unique_ptr<T> make_unique_for_overwrite() {+ return std::unique_ptr<T>(new T);+}++template <class T>+requires std::is_unbounded_array_v<T> std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) {+ return std::unique_ptr<T>(new std::remove_extent_t<T>[n]);+}++template <class T, class... Args>+requires std::is_bounded_array_v<T>+void make_unique_for_overwrite(Args&&...) = delete;++} // namespace Common