summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ameerj2022-12-18 17:44:34 -0500
committerGravatar ameerj2022-12-19 18:07:42 -0500
commit88ba5a7f22b5783e6e19059e49b632d0bd9c8da0 (patch)
tree7b38b9b5cbe45b88b020e968a168f91a87e1a43d /src
parentMerge pull request #9474 from liamwhite/timer (diff)
downloadyuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.gz
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.tar.xz
yuzu-88ba5a7f22b5783e6e19059e49b632d0bd9c8da0.zip
common: add make_unique_for_overwrite
Diffstat (limited to 'src')
-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
78 logging/types.h 78 logging/types.h
79 lz4_compression.cpp 79 lz4_compression.cpp
80 lz4_compression.h 80 lz4_compression.h
81 make_unique_for_overwrite.h
81 math_util.h 82 math_util.h
82 memory_detect.cpp 83 memory_detect.cpp
83 memory_detect.h 84 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 @@
1// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <memory>
7#include <type_traits>
8
9namespace Common {
10
11template <class T>
12requires(!std::is_array_v<T>) std::unique_ptr<T> make_unique_for_overwrite() {
13 return std::unique_ptr<T>(new T);
14}
15
16template <class T>
17requires std::is_unbounded_array_v<T> std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) {
18 return std::unique_ptr<T>(new std::remove_extent_t<T>[n]);
19}
20
21template <class T, class... Args>
22requires std::is_bounded_array_v<T>
23void make_unique_for_overwrite(Args&&...) = delete;
24
25} // namespace Common