2 Copyright 2012-2015 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/config.hpp>
20 typedef std::unique_ptr<T> type;
24 struct up_if_object<T[]> { };
26 template<class T, std::size_t N>
27 struct up_if_object<T[N]> { };
30 struct up_if_array { };
33 struct up_if_array<T[]> {
34 typedef std::unique_ptr<T[]> type;
38 struct up_remove_reference {
43 struct up_remove_reference<T&> {
48 struct up_remove_reference<T&&> {
53 struct up_element { };
56 struct up_element<T[]> {
63 inline typename detail::up_if_object<T>::type
66 return std::unique_ptr<T>(new T());
69 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
70 template<class T, class... Args>
71 inline typename detail::up_if_object<T>::type
72 make_unique(Args&&... args)
74 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
79 inline typename detail::up_if_object<T>::type
80 make_unique(typename detail::up_remove_reference<T>::type&& value)
82 return std::unique_ptr<T>(new T(std::move(value)));
86 inline typename detail::up_if_object<T>::type
89 return std::unique_ptr<T>(new T);
93 inline typename detail::up_if_array<T>::type
94 make_unique(std::size_t size)
96 return std::unique_ptr<T>(new typename
97 detail::up_element<T>::type[size]());
101 inline typename detail::up_if_array<T>::type
102 make_unique_noinit(std::size_t size)
104 return std::unique_ptr<T>(new typename
105 detail::up_element<T>::type[size]);