Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / smart_ptr / make_unique_object.hpp
1 /*
2  * Copyright (c) 2014 Glen Joseph Fernandes
3  * glenfe at live dot com
4  *
5  * Distributed under the Boost Software License,
6  * Version 1.0. (See accompanying file LICENSE_1_0.txt
7  * or copy at http://boost.org/LICENSE_1_0.txt)
8  */
9 #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP
10 #define BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP
11
12 #include <boost/config.hpp>
13 #include <boost/smart_ptr/detail/up_if_not_array.hpp>
14 #include <boost/type_traits/add_rvalue_reference.hpp>
15 #include <utility>
16
17 namespace boost {
18     template<class T>
19     inline typename boost::detail::up_if_not_array<T>::type
20     make_unique() {
21         return std::unique_ptr<T>(new T());
22     }
23
24 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
25     template<class T, class... Args>
26     inline typename boost::detail::up_if_not_array<T>::type
27     make_unique(Args&&... args) {
28         return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
29     }
30 #endif
31     
32     template<class T>
33     inline typename boost::detail::up_if_not_array<T>::type
34     make_unique(typename add_rvalue_reference<T>::type value) {
35         return std::unique_ptr<T>(new T(std::move(value)));
36     }
37
38     template<class T>
39     inline typename boost::detail::up_if_not_array<T>::type
40     make_unique_noinit() {
41         return std::unique_ptr<T>(new T);
42     }
43 }
44
45 #endif