From fa828b8fba18ececb82f02910c05ad85820bca6b Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Mon, 27 Jan 2020 17:48:34 +0100 Subject: STL support: make_unique can now handle array --- Utilities/std/cm/memory | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Utilities/std/cm/memory b/Utilities/std/cm/memory index 8ebded2..dd0f822 100644 --- a/Utilities/std/cm/memory +++ b/Utilities/std/cm/memory @@ -8,6 +8,8 @@ #include // IWYU pragma: export #if !defined(CMake_HAVE_CXX_MAKE_UNIQUE) +# include +# include # include #endif @@ -19,12 +21,45 @@ using std::make_unique; #else +namespace internals { + +template +struct make_unique_if +{ + using single = std::unique_ptr; +}; + +template +struct make_unique_if +{ + using unbound_array = std::unique_ptr; +}; + +template +struct make_unique_if +{ + using bound_array = void; +}; +} + template -std::unique_ptr make_unique(Args&&... args) +typename internals::make_unique_if::single make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } +template +typename internals::make_unique_if::unbound_array make_unique(std::size_t n) +{ + using E = typename std::remove_extent::type; + + return std::unique_ptr(new E[n]()); +} + +template +typename internals::make_unique_if::bound_array make_unique(Args&&...) = + delete; + #endif } // namespace cm -- cgit v0.12