summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2022-12-18 23:44:34 +0100
committerameerj <52414509+ameerj@users.noreply.github.com>2022-12-20 00:07:42 +0100
commit88ba5a7f22b5783e6e19059e49b632d0bd9c8da0 (patch)
tree7b38b9b5cbe45b88b020e968a168f91a87e1a43d /src/common
parentMerge pull request #9474 from liamwhite/timer (diff)
downloadyuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.gz
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.bz2
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.lz
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.xz
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.zst
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/make_unique_for_overwrite.h25
2 files changed, 26 insertions, 0 deletions
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 <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