1/*
2Copyright 2012-2019 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7*/
8#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
9#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
10
11#include <boost/smart_ptr/detail/requires_cxx11.hpp>
12#include <boost/type_traits/enable_if.hpp>
13#include <boost/type_traits/is_array.hpp>
14#include <boost/type_traits/is_unbounded_array.hpp>
15#include <boost/type_traits/remove_extent.hpp>
16#include <boost/type_traits/remove_reference.hpp>
17#include <memory>
18#include <utility>
19
20namespace boost {
21
22template<class T>
23inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
24make_unique()
25{
26 return std::unique_ptr<T>(new T());
27}
28
29#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
30template<class T, class... Args>
31inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
32make_unique(Args&&... args)
33{
34 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
35}
36#endif
37
38template<class T>
39inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
40make_unique(typename remove_reference<T>::type&& value)
41{
42 return std::unique_ptr<T>(new T(std::move(value)));
43}
44
45template<class T>
46inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
47make_unique_noinit()
48{
49 return std::unique_ptr<T>(new T);
50}
51
52template<class T>
53inline typename enable_if_<is_unbounded_array<T>::value,
54 std::unique_ptr<T> >::type
55make_unique(std::size_t size)
56{
57 return std::unique_ptr<T>(new typename remove_extent<T>::type[size]());
58}
59
60template<class T>
61inline typename enable_if_<is_unbounded_array<T>::value,
62 std::unique_ptr<T> >::type
63make_unique_noinit(std::size_t size)
64{
65 return std::unique_ptr<T>(new typename remove_extent<T>::type[size]);
66}
67
68} /* boost */
69
70#endif
71

source code of boost/libs/smart_ptr/include/boost/smart_ptr/make_unique.hpp