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: common: add make_unique_for_overwrite --- src/common/make_unique_for_overwrite.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/common/make_unique_for_overwrite.h (limited to 'src/common/make_unique_for_overwrite.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 -- cgit v1.2.3