diff options
Diffstat (limited to 'src/common/make_unique_for_overwrite.h')
| -rw-r--r-- | src/common/make_unique_for_overwrite.h | 25 |
1 files changed, 25 insertions, 0 deletions
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 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | template <class T> | ||
| 12 | requires(!std::is_array_v<T>) std::unique_ptr<T> make_unique_for_overwrite() { | ||
| 13 | return std::unique_ptr<T>(new T); | ||
| 14 | } | ||
| 15 | |||
| 16 | template <class T> | ||
| 17 | requires 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 | |||
| 21 | template <class T, class... Args> | ||
| 22 | requires std::is_bounded_array_v<T> | ||
| 23 | void make_unique_for_overwrite(Args&&...) = delete; | ||
| 24 | |||
| 25 | } // namespace Common | ||