2 Copyright 2012-2019 Glen Joseph Fernandes
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
9 #define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
11 #include <boost/type_traits/enable_if.hpp>
12 #include <boost/type_traits/is_array.hpp>
13 #include <boost/type_traits/is_unbounded_array.hpp>
14 #include <boost/type_traits/remove_extent.hpp>
15 #include <boost/type_traits/remove_reference.hpp>
22 inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
25 return std::unique_ptr<T>(new T());
28 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
29 template<class T, class... Args>
30 inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
31 make_unique(Args&&... args)
33 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
38 inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
39 make_unique(typename remove_reference<T>::type&& value)
41 return std::unique_ptr<T>(new T(std::move(value)));
45 inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
48 return std::unique_ptr<T>(new T);
52 inline typename enable_if_<is_unbounded_array<T>::value,
53 std::unique_ptr<T> >::type
54 make_unique(std::size_t size)
56 return std::unique_ptr<T>(new typename remove_extent<T>::type[size]());
60 inline typename enable_if_<is_unbounded_array<T>::value,
61 std::unique_ptr<T> >::type
62 make_unique_noinit(std::size_t size)
64 return std::unique_ptr<T>(new typename remove_extent<T>::type[size]);