From 88ba5a7f22b5783e6e19059e49b632d0bd9c8da0 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:44:34 -0500 Subject: [PATCH] common: add make_unique_for_overwrite --- src/common/CMakeLists.txt | 1 + src/common/make_unique_for_overwrite.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/common/make_unique_for_overwrite.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 25b22a281..f558f5a58 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -78,6 +78,7 @@ add_library(common STATIC logging/types.h lz4_compression.cpp lz4_compression.h + make_unique_for_overwrite.h math_util.h memory_detect.cpp memory_detect.h diff --git a/src/common/make_unique_for_overwrite.h b/src/common/make_unique_for_overwrite.h new file mode 100644 index 000000000..c7413cf51 --- /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 +#include + +namespace Common { + +template +requires(!std::is_array_v) std::unique_ptr make_unique_for_overwrite() { + return std::unique_ptr(new T); +} + +template +requires std::is_unbounded_array_v std::unique_ptr make_unique_for_overwrite(std::size_t n) { + return std::unique_ptr(new std::remove_extent_t[n]); +} + +template +requires std::is_bounded_array_v +void make_unique_for_overwrite(Args&&...) = delete; + +} // namespace Common