summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2020-12-07 13:17:57 +0300
committerVasily Melenchuk <vasily.melenchuk@cib.de>2020-12-07 13:17:57 +0300
commita3133d829fe29ca177329790289c3f8f552a5326 (patch)
tree6050e73d70e098687c461cdb1b8fe66cb7ca1ae5 /include
parent27c6a0f9a0e6f0fa18a21033ed31bfbc01b0a6c4 (diff)
Revert "Drop include/o3tl/make_unique.hxx"
This reverts commit 97d68765d24c1a9e0715063b4f9c65585281a869.
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/make_unique.hxx51
1 files changed, 51 insertions, 0 deletions
diff --git a/include/o3tl/make_unique.hxx b/include/o3tl/make_unique.hxx
new file mode 100644
index 000000000000..555e9ca538b8
--- /dev/null
+++ b/include/o3tl/make_unique.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_MAKE_UNIQUE_HXX
+#define INCLUDED_O3TL_MAKE_UNIQUE_HXX
+
+#include <memory>
+#include <utility>
+#include <type_traits>
+
+namespace o3tl
+{
+
+/**
+ * Constructs an object of type T and wraps it in a std::unique_ptr.
+ *
+ * Can be replaced by std::make_unique when we allow C++14.
+ */
+template<typename T, typename... Args>
+typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
+make_unique(Args&& ... args)
+{
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+/**
+ * for arrays
+ */
+template <class T>
+typename std::enable_if
+<
+ std::is_array<T>::value,
+ std::unique_ptr<T>
+>::type
+make_unique(std::size_t n)
+{
+ typedef typename std::remove_extent<T>::type RT;
+ return std::unique_ptr<T>(new RT[n]);
+}
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */