summaryrefslogtreecommitdiff
path: root/src/common/utils2.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/utils2.hpp')
-rw-r--r--src/common/utils2.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp
index cdf2069..5f02beb 100644
--- a/src/common/utils2.hpp
+++ b/src/common/utils2.hpp
@@ -5,6 +5,7 @@
#include <functional>
#include <iterator>
+#include <memory>
#include <type_traits>
#ifdef __clang__
@@ -208,4 +209,22 @@ typename std::common_type<A, B>::type max(A a, B b)
return b < a ? a : b;
}
+template<class T>
+struct is_array_of_unknown_bound
+: std::is_same<T, typename std::remove_extent<T>::type[]>
+{};
+
+template<class T, class... A>
+typename std::enable_if<!is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(A&&... a)
+{
+ return std::unique_ptr<T>(new T(a...));
+}
+
+template<class T>
+typename std::enable_if<is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(size_t sz)
+{
+ typedef typename std::remove_extent<T>::type E;
+ return std::unique_ptr<E[]>(new E[sz]);
+}
+
#endif // UTILS2_HPP