diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-18 23:44:34 +0100 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-20 00:07:42 +0100 |
commit | 88ba5a7f22b5783e6e19059e49b632d0bd9c8da0 (patch) | |
tree | 7b38b9b5cbe45b88b020e968a168f91a87e1a43d /src/common | |
parent | Merge pull request #9474 from liamwhite/timer (diff) | |
download | yuzu-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 '')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/make_unique_for_overwrite.h | 25 |
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 |