Skip to content
Snippets Groups Projects
Commit f13ca2eb authored by Danilo Piparo's avatar Danilo Piparo
Browse files

[Core][ROOT-10086] Add make_unique backport for arrays

parent 22c32d30
No related branches found
No related tags found
Loading
/// \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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment