From f13ca2eb477801e199d9336f19d9ea1ab0b603aa Mon Sep 17 00:00:00 2001
From: Danilo Piparo <danilo.piparo@cern.ch>
Date: Mon, 15 Apr 2019 16:35:00 +0200
Subject: [PATCH] [Core][ROOT-10086] Add make_unique backport for arrays

---
 core/foundation/inc/ROOT/RMakeUnique.hxx | 37 ++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/core/foundation/inc/ROOT/RMakeUnique.hxx b/core/foundation/inc/ROOT/RMakeUnique.hxx
index 91ac54695ab..ed67470a12e 100644
--- a/core/foundation/inc/ROOT/RMakeUnique.hxx
+++ b/core/foundation/inc/ROOT/RMakeUnique.hxx
@@ -1,10 +1,10 @@
-/// \file ROOT/RMakeUnique.h
+/// \file ROOT/RMakeUnique.hxx
 /// \ingroup Base StdExt
 /// \author Danilo Piparo
 /// \date 2017-09-22
 
 /*************************************************************************
- * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers.               *
+ * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
  * All rights reserved.                                                  *
  *                                                                       *
  * For the licensing terms see $ROOTSYS/LICENSE.                         *
@@ -18,16 +18,47 @@
 
 #if __cplusplus < 201402L && !defined(_MSC_VER)
 
+#include <type_traits>
 #include <utility>
 
+namespace ROOT {
+namespace Detail {
+// Inspired from abseil
+template <typename T>
+struct RMakeUniqueResult {
+   using scalar = std::unique_ptr<T>;
+};
+template <typename T>
+struct RMakeUniqueResult<T[]> {
+   using array = std::unique_ptr<T[]>;
+};
+template <typename T, size_t N>
+struct RMakeUniqueResult<T[N]> {
+   using invalid = void;
+};
+} // namespace Detail
+} // namespace ROOT
+
 namespace std {
 
+// template <typename T, typename... Args, typename std::enable_if<!std::is_array<T>::value, int>::type = 0>
 template <typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args &&... args)
+typename ROOT::Detail::RMakeUniqueResult<T>::scalar make_unique(Args &&... args)
 {
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
 }
+
+template <typename T>
+typename ROOT::Detail::RMakeUniqueResult<T>::array make_unique(std::size_t size)
+{
+   return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
 }
+
+template <typename T, typename... Args>
+typename ROOT::Detail::RMakeUniqueResult<T>::invalid make_unique(Args &&...) = delete;
+
+
+} // namespace std
 #endif
 
 #endif
-- 
GitLab