]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/move/make_unique.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / move / make_unique.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2014. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/move for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED
12 #define BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/move/detail/config_begin.hpp>
23 #include <boost/move/detail/workaround.hpp>
24 #include <boost/move/utility_core.hpp>
25 #include <boost/move/unique_ptr.hpp>
26 #include <cstddef> //for std::size_t
27 #include <boost/move/detail/unique_ptr_meta_utils.hpp>
28 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
29 # include <boost/move/detail/fwd_macros.hpp>
30 #endif
31
32 //!\file
33 //! Defines "make_unique" functions, which are factories to create instances
34 //! of unique_ptr depending on the passed arguments.
35 //!
36 //! This header can be a bit heavyweight in C++03 compilers due to the use of the
37 //! preprocessor library, that's why it's a a separate header from <tt>unique_ptr.hpp</tt>
38
39 #if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
40
41 #if defined(_MSC_VER) && (_MSC_VER >= 1915)
42 #pragma warning (push)
43 #pragma warning (disable : 4643) // Forward declaring 'X' in namespace std is not permitted by the C++ Standard
44 #endif
45
46 namespace std { //no namespace versioning in clang+libc++
47
48 struct nothrow_t;
49
50 } //namespace std {
51
52 #if defined(_MSC_VER) && (_MSC_VER >= 1915)
53 #pragma warning (pop)
54 #endif
55
56
57 namespace boost{
58 namespace move_upmu {
59
60 //Compile time switch between
61 //single element, unknown bound array
62 //and known bound array
63 template<class T>
64 struct unique_ptr_if
65 {
66 typedef ::boost::movelib::unique_ptr<T> t_is_not_array;
67 };
68
69 template<class T>
70 struct unique_ptr_if<T[]>
71 {
72 typedef ::boost::movelib::unique_ptr<T[]> t_is_array_of_unknown_bound;
73 };
74
75 template<class T, std::size_t N>
76 struct unique_ptr_if<T[N]>
77 {
78 typedef void t_is_array_of_known_bound;
79 };
80
81 template <int Dummy = 0>
82 struct nothrow_holder
83 {
84 static std::nothrow_t *pnothrow;
85 };
86
87 template <int Dummy>
88 std::nothrow_t *nothrow_holder<Dummy>::pnothrow =
89 reinterpret_cast<std::nothrow_t *>(0x1234); //Avoid reference to null errors in sanitizers
90
91 } //namespace move_upmu {
92 } //namespace boost{
93
94 #endif //!defined(BOOST_MOVE_DOXYGEN_INVOKED)
95
96 namespace boost{
97 namespace movelib {
98
99 #if defined(BOOST_MOVE_DOXYGEN_INVOKED) || !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
100
101 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
102 //!
103 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::forward<Args>(args)...))</tt>.
104 template<class T, class... Args>
105 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
106 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
107 make_unique(BOOST_FWD_REF(Args)... args)
108 { return unique_ptr<T>(new T(::boost::forward<Args>(args)...)); }
109
110 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
111 //!
112 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::nothrow)(std::forward<Args>(args)...))</tt>.
113 template<class T, class... Args>
114 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
115 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
116 make_unique_nothrow(BOOST_FWD_REF(Args)... args)
117 { return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)T(::boost::forward<Args>(args)...)); }
118
119 #else
120 #define BOOST_MOVE_MAKE_UNIQUE_CODE(N)\
121 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
122 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array\
123 make_unique( BOOST_MOVE_UREF##N)\
124 { return unique_ptr<T>( new T( BOOST_MOVE_FWD##N ) ); }\
125 \
126 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
127 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array\
128 make_unique_nothrow( BOOST_MOVE_UREF##N)\
129 { return unique_ptr<T>( new (*boost::move_upmu::nothrow_holder<>::pnothrow)T ( BOOST_MOVE_FWD##N ) ); }\
130 //
131 BOOST_MOVE_ITERATE_0TO9(BOOST_MOVE_MAKE_UNIQUE_CODE)
132 #undef BOOST_MOVE_MAKE_UNIQUE_CODE
133
134 #endif
135
136 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
137 //!
138 //! <b>Returns</b>: <tt>unique_ptr<T>(new T)</tt> (default initialization)
139 template<class T>
140 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
141 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
142 make_unique_definit()
143 {
144 return unique_ptr<T>(new T);
145 }
146
147 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
148 //!
149 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::nothrow)</tt> (default initialization)
150 template<class T>
151 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
152 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
153 make_unique_nothrow_definit()
154 {
155 return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)T);
156 }
157
158 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of
159 //! unknown bound.
160 //!
161 //! <b>Returns</b>: <tt>unique_ptr<T>(new remove_extent_t<T>[n]())</tt> (value initialization)
162 template<class T>
163 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
164 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
165 make_unique(std::size_t n)
166 {
167 typedef typename ::boost::move_upmu::remove_extent<T>::type U;
168 return unique_ptr<T>(new U[n]());
169 }
170
171 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of
172 //! unknown bound.
173 //!
174 //! <b>Returns</b>: <tt>unique_ptr<T>(new (std::nothrow)remove_extent_t<T>[n]())</tt> (value initialization)
175 template<class T>
176 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
177 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
178 make_unique_nothrow(std::size_t n)
179 {
180 typedef typename ::boost::move_upmu::remove_extent<T>::type U;
181 return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)U[n]());
182 }
183
184 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of
185 //! unknown bound.
186 //!
187 //! <b>Returns</b>: <tt>unique_ptr<T>(new remove_extent_t<T>[n])</tt> (default initialization)
188 template<class T>
189 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
190 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
191 make_unique_definit(std::size_t n)
192 {
193 typedef typename ::boost::move_upmu::remove_extent<T>::type U;
194 return unique_ptr<T>(new U[n]);
195 }
196
197 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of
198 //! unknown bound.
199 //!
200 //! <b>Returns</b>: <tt>unique_ptr<T>(new (std::nothrow)remove_extent_t<T>[n])</tt> (default initialization)
201 template<class T>
202 inline BOOST_MOVE_DOC1ST(unique_ptr<T>,
203 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
204 make_unique_nothrow_definit(std::size_t n)
205 {
206 typedef typename ::boost::move_upmu::remove_extent<T>::type U;
207 return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow) U[n]);
208 }
209
210 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
211
212 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
213 //! an array of known bound.
214 template<class T, class... Args>
215 inline BOOST_MOVE_DOC1ST(unspecified,
216 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
217 make_unique(BOOST_FWD_REF(Args) ...) = delete;
218
219 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
220 //! an array of known bound.
221 template<class T, class... Args>
222 inline BOOST_MOVE_DOC1ST(unspecified,
223 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
224 make_unique_definit(BOOST_FWD_REF(Args) ...) = delete;
225
226 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
227 //! an array of known bound.
228 template<class T, class... Args>
229 inline BOOST_MOVE_DOC1ST(unspecified,
230 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
231 make_unique_nothrow(BOOST_FWD_REF(Args) ...) = delete;
232
233 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
234 //! an array of known bound.
235 template<class T, class... Args>
236 inline BOOST_MOVE_DOC1ST(unspecified,
237 typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
238 make_unique_nothrow_definit(BOOST_FWD_REF(Args) ...) = delete;
239
240 #endif
241
242 } //namespace movelib {
243
244 } //namespace boost{
245
246 #include <boost/move/detail/config_end.hpp>
247
248 #endif //#ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED