1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // (C) Copyright John Maddock 2000. |
3 | // (C) Copyright Ion Gaztanaga 2005-2015. |
4 | // |
5 | // Distributed under the Boost Software License, Version 1.0. |
6 | // (See accompanying file LICENSE_1_0.txt or copy at |
7 | // http://www.boost.org/LICENSE_1_0.txt) |
8 | // |
9 | // See http://www.boost.org/libs/move for documentation. |
10 | // |
11 | // The alignment and Type traits implementation comes from |
12 | // John Maddock's TypeTraits library. |
13 | // |
14 | // Some other tricks come from Howard Hinnant's papers and StackOverflow replies |
15 | ////////////////////////////////////////////////////////////////////////////// |
16 | #ifndef BOOST_MOVE_DETAIL_TYPE_TRAITS_HPP |
17 | #define BOOST_MOVE_DETAIL_TYPE_TRAITS_HPP |
18 | |
19 | #ifndef BOOST_CONFIG_HPP |
20 | # include <boost/config.hpp> |
21 | #endif |
22 | # |
23 | #if defined(BOOST_HAS_PRAGMA_ONCE) |
24 | # pragma once |
25 | #endif |
26 | |
27 | #include <boost/move/detail/config_begin.hpp> |
28 | #include <boost/move/detail/workaround.hpp> |
29 | |
30 | // move/detail |
31 | #include <boost/move/detail/meta_utils.hpp> |
32 | // other |
33 | #include <boost/assert.hpp> |
34 | #include <boost/static_assert.hpp> |
35 | // std |
36 | #include <cstddef> |
37 | |
38 | //Use of Boost.TypeTraits leads to long preprocessed source code due to |
39 | //MPL dependencies. We'll use intrinsics directly and make or own |
40 | //simplified version of TypeTraits. |
41 | //If someday Boost.TypeTraits dependencies are minimized, we should |
42 | //revisit this file redirecting code to Boost.TypeTraits traits. |
43 | |
44 | //These traits don't care about volatile, reference or other checks |
45 | //made by Boost.TypeTraits because no volatile or reference types |
46 | //can be hold in Boost.Containers. This helps to avoid any Boost.TypeTraits |
47 | //dependency. |
48 | |
49 | // Helper macros for builtin compiler support. |
50 | // If your compiler has builtin support for any of the following |
51 | // traits concepts, then redefine the appropriate macros to pick |
52 | // up on the compiler support: |
53 | // |
54 | // (these should largely ignore cv-qualifiers) |
55 | // BOOST_MOVE_IS_POD(T) should evaluate to true if T is a POD type |
56 | // BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) should evaluate to true if "T x;" has no effect |
57 | // BOOST_MOVE_HAS_TRIVIAL_COPY(T) should evaluate to true if T(t) <==> memcpy |
58 | // BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) should evaluate to true if T(boost::move(t)) <==> memcpy |
59 | // BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) should evaluate to true if t = u <==> memcpy |
60 | // BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) should evaluate to true if t = boost::move(u) <==> memcpy |
61 | // BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) should evaluate to true if ~T() has no effect |
62 | // BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) should evaluate to true if "T x;" can not throw |
63 | // BOOST_MOVE_HAS_NOTHROW_COPY(T) should evaluate to true if T(t) can not throw |
64 | // BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) should evaluate to true if t = u can not throw |
65 | // BOOST_MOVE_IS_ENUM(T) should evaluate to true it t is a union type. |
66 | // |
67 | // The following can also be defined: when detected our implementation is greatly simplified. |
68 | // |
69 | // BOOST_ALIGNMENT_OF(T) should evaluate to the alignment requirements of type T. |
70 | |
71 | #if defined(__MSL_CPP__) && (__MSL_CPP__ >= 0x8000) |
72 | // Metrowerks compiler is acquiring intrinsic type traits support |
73 | // post version 8. We hook into the published interface to pick up |
74 | // user defined specializations as well as compiler intrinsics as |
75 | // and when they become available: |
76 | # include <msl_utility> |
77 | # define BOOST_MOVE_IS_UNION(T) BOOST_STD_EXTENSION_NAMESPACE::is_union<T>::value |
78 | # define BOOST_MOVE_IS_POD(T) BOOST_STD_EXTENSION_NAMESPACE::is_POD<T>::value |
79 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_default_ctor<T>::value |
80 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_copy_ctor<T>::value |
81 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_assignment<T>::value |
82 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_dtor<T>::value |
83 | #endif |
84 | |
85 | #if (defined(BOOST_MSVC) && defined(BOOST_MSVC_FULL_VER) && (BOOST_MSVC_FULL_VER >=140050215))\ |
86 | || (defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1500)) |
87 | # define BOOST_MOVE_IS_UNION(T) __is_union(T) |
88 | # define BOOST_MOVE_IS_POD(T) (__is_pod(T) && __has_trivial_constructor(T)) |
89 | # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T) |
90 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T) |
91 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T)|| ::boost::move_detail::is_pod<T>::value) |
92 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) || ::boost::move_detail::is_pod<T>::value) |
93 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) || ::boost::move_detail::is_pod<T>::value) |
94 | # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) || ::boost::move_detail::is_trivially_default_constructible<T>::value) |
95 | # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T) || ::boost::move_detail::is_trivially_copy_constructible<T>::value) |
96 | # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) || ::boost::move_detail::is_trivially_copy_assignable<T>::value) |
97 | |
98 | # define BOOST_MOVE_IS_ENUM(T) __is_enum(T) |
99 | # if defined(_MSC_VER) && (_MSC_VER >= 1700) |
100 | # define BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__has_trivial_move_constructor(T) || ::boost::move_detail::is_pod<T>::value) |
101 | # define BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) (__has_trivial_move_assign(T) || ::boost::move_detail::is_pod<T>::value) |
102 | # endif |
103 | #endif |
104 | |
105 | #if defined(BOOST_CLANG) && defined(__has_feature) |
106 | |
107 | # if __has_feature(is_union) |
108 | # define BOOST_MOVE_IS_UNION(T) __is_union(T) |
109 | # endif |
110 | # if (!defined(__GLIBCXX__) || (__GLIBCXX__ >= 20080306 && __GLIBCXX__ != 20080519)) && __has_feature(is_pod) |
111 | # define BOOST_MOVE_IS_POD(T) __is_pod(T) |
112 | # endif |
113 | # if (!defined(__GLIBCXX__) || (__GLIBCXX__ >= 20080306 && __GLIBCXX__ != 20080519)) && __has_feature(is_empty) |
114 | # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T) |
115 | # endif |
116 | # if __has_feature(has_trivial_constructor) |
117 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T) |
118 | # endif |
119 | # if __has_feature(has_trivial_copy) |
120 | # //There are problems with deleted copy constructors detected as trivially copyable. |
121 | # //http://stackoverflow.com/questions/12754886/has-trivial-copy-behaves-differently-in-clang-and-gcc-whos-right |
122 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && ::boost::move_detail::is_copy_constructible<T>::value) |
123 | # endif |
124 | # if __has_feature(has_trivial_assign) |
125 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) ) |
126 | # endif |
127 | # if __has_feature(has_trivial_destructor) |
128 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) |
129 | # endif |
130 | # if __has_feature(has_nothrow_constructor) |
131 | # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) __has_nothrow_constructor(T) |
132 | # endif |
133 | # if __has_feature(has_nothrow_copy) |
134 | # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T)) |
135 | # endif |
136 | # if __has_feature(is_nothrow_copy_assignable) |
137 | # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T)) |
138 | # endif |
139 | # if __has_feature(is_enum) |
140 | # define BOOST_MOVE_IS_ENUM(T) __is_enum(T) |
141 | # endif |
142 | # if __has_feature(has_trivial_move_constructor) |
143 | # define BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) __has_trivial_move_constructor(T) |
144 | # endif |
145 | # if __has_feature(has_trivial_move_assign) |
146 | # define BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) __has_trivial_move_assign(T) |
147 | # endif |
148 | # define BOOST_MOVE_ALIGNMENT_OF(T) __alignof(T) |
149 | #endif |
150 | |
151 | #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) && !defined(__GCCXML__))) && !defined(BOOST_CLANG) |
152 | |
153 | #ifdef BOOST_INTEL |
154 | # define BOOST_MOVE_INTEL_TT_OPTS || ::boost::move_detail::is_pod<T>::value |
155 | #else |
156 | # define BOOST_MOVE_INTEL_TT_OPTS |
157 | #endif |
158 | |
159 | # define BOOST_MOVE_IS_UNION(T) __is_union(T) |
160 | # define BOOST_MOVE_IS_POD(T) __is_pod(T) |
161 | # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T) |
162 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) ((__has_trivial_constructor(T) BOOST_MOVE_INTEL_TT_OPTS)) |
163 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) ((__has_trivial_copy(T) BOOST_MOVE_INTEL_TT_OPTS)) |
164 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) ((__has_trivial_assign(T) BOOST_MOVE_INTEL_TT_OPTS) ) |
165 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) BOOST_MOVE_INTEL_TT_OPTS) |
166 | # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) BOOST_MOVE_INTEL_TT_OPTS) |
167 | # define BOOST_MOVE_HAS_NOTHROW_COPY(T) ((__has_nothrow_copy(T) BOOST_MOVE_INTEL_TT_OPTS)) |
168 | # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) ((__has_nothrow_assign(T) BOOST_MOVE_INTEL_TT_OPTS)) |
169 | |
170 | # define BOOST_MOVE_IS_ENUM(T) __is_enum(T) |
171 | # if (!defined(unix) && !defined(__unix__)) || defined(__LP64__) |
172 | // GCC sometimes lies about alignment requirements |
173 | // of type double on 32-bit unix platforms, use the |
174 | // old implementation instead in that case: |
175 | # define BOOST_MOVE_ALIGNMENT_OF(T) __alignof__(T) |
176 | # endif |
177 | #endif |
178 | |
179 | #if defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600) |
180 | |
181 | # define BOOST_MOVE_IS_UNION(T) __is_union(T) |
182 | # define BOOST_MOVE_IS_POD(T) __is_pod(T) |
183 | # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T) |
184 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T) |
185 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T)) |
186 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T)) |
187 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) |
188 | # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) __has_nothrow_constructor(T) |
189 | # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T)) |
190 | # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T)) |
191 | |
192 | # define BOOST_MOVE_IS_ENUM(T) __is_enum(T) |
193 | # define BOOST_MOVE_ALIGNMENT_OF(T) __alignof__(T) |
194 | #endif |
195 | |
196 | # if defined(__CODEGEARC__) |
197 | # define BOOST_MOVE_IS_UNION(T) __is_union(T) |
198 | # define BOOST_MOVE_IS_POD(T) __is_pod(T) |
199 | # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T) |
200 | # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) (__has_trivial_default_constructor(T)) |
201 | # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) (__has_trivial_copy_constructor(T)) |
202 | # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T)) |
203 | # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T)) |
204 | # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_default_constructor(T)) |
205 | # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy_constructor(T)) |
206 | # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T)) |
207 | |
208 | # define BOOST_MOVE_IS_ENUM(T) __is_enum(T) |
209 | # define BOOST_MOVE_ALIGNMENT_OF(T) alignof(T) |
210 | |
211 | #endif |
212 | |
213 | //Fallback definitions |
214 | |
215 | #ifdef BOOST_MOVE_IS_UNION |
216 | #define BOOST_MOVE_IS_UNION_IMPL(T) BOOST_MOVE_IS_UNION(T) |
217 | #else |
218 | #define BOOST_MOVE_IS_UNION_IMPL(T) false |
219 | #endif |
220 | |
221 | #ifdef BOOST_MOVE_IS_POD |
222 | #define BOOST_MOVE_IS_POD_IMPL(T) BOOST_MOVE_IS_POD(T) |
223 | #else |
224 | #define BOOST_MOVE_IS_POD_IMPL(T) \ |
225 | (::boost::move_detail::is_scalar<T>::value || ::boost::move_detail::is_void<T>::value) |
226 | #endif |
227 | |
228 | #ifdef BOOST_MOVE_IS_EMPTY |
229 | #define BOOST_MOVE_IS_EMPTY_IMPL(T) BOOST_MOVE_IS_EMPTY(T) |
230 | #else |
231 | #define BOOST_MOVE_IS_EMPTY_IMPL(T) ::boost::move_detail::is_empty_nonintrinsic<T>::value |
232 | #endif |
233 | |
234 | #ifdef BOOST_MOVE_HAS_TRIVIAL_COPY |
235 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_COPY(T) |
236 | #else |
237 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
238 | #endif |
239 | |
240 | #ifdef BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR |
241 | #define BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) |
242 | #else |
243 | #define BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
244 | #endif |
245 | |
246 | #ifdef BOOST_MOVE_HAS_TRIVIAL_COPY |
247 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_COPY(T) |
248 | #else |
249 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
250 | #endif |
251 | |
252 | #ifdef BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR |
253 | #define BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) |
254 | #else |
255 | #define BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
256 | #endif |
257 | |
258 | #ifdef BOOST_MOVE_HAS_TRIVIAL_ASSIGN |
259 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T) BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) |
260 | #else |
261 | #define BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value |
262 | #endif |
263 | |
264 | #ifdef BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN |
265 | #define BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T) BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) |
266 | #else |
267 | #define BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value |
268 | #endif |
269 | |
270 | #ifdef BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR |
271 | #define BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) |
272 | #else |
273 | #define BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
274 | #endif |
275 | |
276 | #ifdef BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR |
277 | #define BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) |
278 | #else |
279 | #define BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
280 | #endif |
281 | |
282 | #ifdef BOOST_MOVE_HAS_NOTHROW_COPY |
283 | #define BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_COPY(T) |
284 | #else |
285 | #define BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
286 | #endif |
287 | |
288 | #ifdef BOOST_MOVE_HAS_NOTHROW_MOVE |
289 | #define BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_MOVE(T) |
290 | #else |
291 | #define BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value |
292 | #endif |
293 | |
294 | #ifdef BOOST_MOVE_HAS_NOTHROW_ASSIGN |
295 | #define BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T) BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) |
296 | #else |
297 | #define BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value |
298 | #endif |
299 | |
300 | #ifdef BOOST_MOVE_HAS_NOTHROW_MOVE_ASSIGN |
301 | #define BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T) BOOST_MOVE_HAS_NOTHROW_MOVE_ASSIGN(T) |
302 | #else |
303 | #define BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value |
304 | #endif |
305 | |
306 | #ifdef BOOST_MOVE_IS_ENUM |
307 | #define BOOST_MOVE_IS_ENUM_IMPL(T) BOOST_MOVE_IS_ENUM(T) |
308 | #else |
309 | #define BOOST_MOVE_IS_ENUM_IMPL(T) ::boost::move_detail::is_enum_nonintrinsic<T>::value |
310 | #endif |
311 | |
312 | namespace boost { |
313 | namespace move_detail { |
314 | |
315 | ////////////////////////// |
316 | // is_reference |
317 | ////////////////////////// |
318 | template<class T> |
319 | struct is_reference |
320 | { static const bool value = false; }; |
321 | |
322 | template<class T> |
323 | struct is_reference<T&> |
324 | { static const bool value = true; }; |
325 | |
326 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) |
327 | template<class T> |
328 | struct is_reference<T&&> |
329 | { static const bool value = true; }; |
330 | #endif |
331 | |
332 | ////////////////////////// |
333 | // is_pointer |
334 | ////////////////////////// |
335 | template<class T> |
336 | struct is_pointer |
337 | { static const bool value = false; }; |
338 | |
339 | template<class T> |
340 | struct is_pointer<T*> |
341 | { static const bool value = true; }; |
342 | |
343 | ////////////////////////// |
344 | // add_reference |
345 | ////////////////////////// |
346 | template <typename T> |
347 | struct add_reference |
348 | { typedef T& type; }; |
349 | |
350 | template<class T> |
351 | struct add_reference<T&> |
352 | { typedef T& type; }; |
353 | |
354 | template<> |
355 | struct add_reference<void> |
356 | { typedef nat &type; }; |
357 | |
358 | template<> |
359 | struct add_reference<const void> |
360 | { typedef const nat &type; }; |
361 | |
362 | ////////////////////////// |
363 | // add_const_reference |
364 | ////////////////////////// |
365 | template <class T> |
366 | struct add_const_reference |
367 | { typedef const T &type; }; |
368 | |
369 | template <class T> |
370 | struct add_const_reference<T&> |
371 | { typedef T& type; }; |
372 | |
373 | ////////////////////////// |
374 | // remove_const |
375 | ////////////////////////// |
376 | template<class T> |
377 | struct remove_const |
378 | { typedef T type; }; |
379 | |
380 | template<class T> |
381 | struct remove_const< const T> |
382 | { typedef T type; }; |
383 | |
384 | ////////////////////////// |
385 | // remove_cv |
386 | ////////////////////////// |
387 | template<typename T> struct remove_cv { typedef T type; }; |
388 | template<typename T> struct remove_cv<const T> { typedef T type; }; |
389 | template<typename T> struct remove_cv<const volatile T> { typedef T type; }; |
390 | template<typename T> struct remove_cv<volatile T> { typedef T type; }; |
391 | |
392 | ////////////////////////// |
393 | // make_unsigned |
394 | ////////////////////////// |
395 | template <class T> |
396 | struct make_unsigned_impl { typedef T type; }; |
397 | template <> struct make_unsigned_impl<signed char> { typedef unsigned char type; }; |
398 | template <> struct make_unsigned_impl<signed short> { typedef unsigned short type; }; |
399 | template <> struct make_unsigned_impl<signed int> { typedef unsigned int type; }; |
400 | template <> struct make_unsigned_impl<signed long> { typedef unsigned long type; }; |
401 | #ifdef BOOST_HAS_LONG_LONG |
402 | template <> struct make_unsigned_impl< ::boost::long_long_type > { typedef ::boost::ulong_long_type type; }; |
403 | #endif |
404 | |
405 | template <class T> |
406 | struct make_unsigned |
407 | : make_unsigned_impl<typename remove_cv<T>::type> |
408 | {}; |
409 | |
410 | ////////////////////////// |
411 | // is_floating_point |
412 | ////////////////////////// |
413 | template<class T> struct is_floating_point_cv { static const bool value = false; }; |
414 | template<> struct is_floating_point_cv<float> { static const bool value = true; }; |
415 | template<> struct is_floating_point_cv<double> { static const bool value = true; }; |
416 | template<> struct is_floating_point_cv<long double> { static const bool value = true; }; |
417 | |
418 | template<class T> |
419 | struct is_floating_point |
420 | : is_floating_point_cv<typename remove_cv<T>::type> |
421 | {}; |
422 | |
423 | ////////////////////////// |
424 | // is_integral |
425 | ////////////////////////// |
426 | template<class T> struct is_integral_cv { static const bool value = false; }; |
427 | template<> struct is_integral_cv< bool>{ static const bool value = true; }; |
428 | template<> struct is_integral_cv< char>{ static const bool value = true; }; |
429 | template<> struct is_integral_cv< unsigned char>{ static const bool value = true; }; |
430 | template<> struct is_integral_cv< signed char>{ static const bool value = true; }; |
431 | #ifndef BOOST_NO_CXX11_CHAR16_T |
432 | template<> struct is_integral_cv< char16_t>{ static const bool value = true; }; |
433 | #endif |
434 | #ifndef BOOST_NO_CXX11_CHAR32_T |
435 | template<> struct is_integral_cv< char32_t>{ static const bool value = true; }; |
436 | #endif |
437 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T |
438 | template<> struct is_integral_cv< wchar_t>{ static const bool value = true; }; |
439 | #endif |
440 | template<> struct is_integral_cv< short>{ static const bool value = true; }; |
441 | template<> struct is_integral_cv< unsigned short>{ static const bool value = true; }; |
442 | template<> struct is_integral_cv< int>{ static const bool value = true; }; |
443 | template<> struct is_integral_cv< unsigned int>{ static const bool value = true; }; |
444 | template<> struct is_integral_cv< long>{ static const bool value = true; }; |
445 | template<> struct is_integral_cv< unsigned long>{ static const bool value = true; }; |
446 | #ifdef BOOST_HAS_LONG_LONG |
447 | template<> struct is_integral_cv< ::boost:: long_long_type>{ static const bool value = true; }; |
448 | template<> struct is_integral_cv< ::boost::ulong_long_type>{ static const bool value = true; }; |
449 | #endif |
450 | |
451 | template<class T> |
452 | struct is_integral |
453 | : public is_integral_cv<typename remove_cv<T>::type> |
454 | {}; |
455 | |
456 | ////////////////////////////////////// |
457 | // remove_all_extents |
458 | ////////////////////////////////////// |
459 | template <class T> |
460 | struct remove_all_extents |
461 | { typedef T type;}; |
462 | |
463 | template <class T> |
464 | struct remove_all_extents<T[]> |
465 | { typedef typename remove_all_extents<T>::type type; }; |
466 | |
467 | template <class T, size_t N> |
468 | struct remove_all_extents<T[N]> |
469 | { typedef typename remove_all_extents<T>::type type;}; |
470 | |
471 | ////////////////////////// |
472 | // is_scalar |
473 | ////////////////////////// |
474 | template<class T> |
475 | struct is_scalar |
476 | { static const bool value = is_integral<T>::value || is_floating_point<T>::value; }; |
477 | |
478 | ////////////////////////// |
479 | // is_void |
480 | ////////////////////////// |
481 | template<class T> |
482 | struct is_void_cv |
483 | { static const bool value = false; }; |
484 | |
485 | template<> |
486 | struct is_void_cv<void> |
487 | { static const bool value = true; }; |
488 | |
489 | template<class T> |
490 | struct is_void |
491 | : is_void_cv<typename remove_cv<T>::type> |
492 | {}; |
493 | |
494 | ////////////////////////////////////// |
495 | // is_array |
496 | ////////////////////////////////////// |
497 | template<class T> |
498 | struct is_array |
499 | { static const bool value = false; }; |
500 | |
501 | template<class T> |
502 | struct is_array<T[]> |
503 | { static const bool value = true; }; |
504 | |
505 | template<class T, std::size_t N> |
506 | struct is_array<T[N]> |
507 | { static const bool value = true; }; |
508 | |
509 | ////////////////////////////////////// |
510 | // is_member_pointer |
511 | ////////////////////////////////////// |
512 | template <class T> struct is_member_pointer_cv { static const bool value = false; }; |
513 | template <class T, class U>struct is_member_pointer_cv<T U::*> { static const bool value = true; }; |
514 | |
515 | template <class T> |
516 | struct is_member_pointer |
517 | : is_member_pointer_cv<typename remove_cv<T>::type> |
518 | {}; |
519 | |
520 | ////////////////////////////////////// |
521 | // is_nullptr_t |
522 | ////////////////////////////////////// |
523 | template <class T> |
524 | struct is_nullptr_t_cv |
525 | { static const bool value = false; }; |
526 | |
527 | #if !defined(BOOST_NO_CXX11_NULLPTR) |
528 | template <> |
529 | struct is_nullptr_t_cv |
530 | #if !defined(BOOST_NO_CXX11_DECLTYPE) |
531 | <decltype(nullptr)> |
532 | #else |
533 | <std::nullptr_t> |
534 | #endif |
535 | { static const bool value = true; }; |
536 | #endif |
537 | |
538 | template <class T> |
539 | struct is_nullptr_t |
540 | : is_nullptr_t_cv<typename remove_cv<T>::type> |
541 | {}; |
542 | |
543 | ////////////////////////////////////// |
544 | // is_function |
545 | ////////////////////////////////////// |
546 | //Inspired by libc++, thanks to Howard Hinnant |
547 | //For a function to pointer an lvalue of function type T can be implicitly converted to a prvalue |
548 | //pointer to that function. This does not apply to non-static member functions because lvalues |
549 | //that refer to non-static member functions do not exist. |
550 | template <class T> |
551 | struct is_reference_convertible_to_pointer |
552 | { |
553 | struct twochar { char dummy[2]; }; |
554 | template <class U> static char test(U*); |
555 | template <class U> static twochar test(...); |
556 | static T& source(); |
557 | static const bool value = sizeof(char) == sizeof(test<T>(source())); |
558 | }; |
559 | //Filter out: |
560 | // - class types that might have implicit conversions |
561 | // - void (to avoid forming a reference to void later) |
562 | // - references (e.g.: filtering reference to functions) |
563 | // - nullptr_t (convertible to pointer) |
564 | template < class T |
565 | , bool Filter = is_class_or_union<T>::value || |
566 | is_void<T>::value || |
567 | is_reference<T>::value || |
568 | is_nullptr_t<T>::value > |
569 | struct is_function_impl |
570 | { static const bool value = is_reference_convertible_to_pointer<T>::value; }; |
571 | |
572 | template <class T> |
573 | struct is_function_impl<T, true> |
574 | { static const bool value = false; }; |
575 | |
576 | template <class T> |
577 | struct is_function |
578 | : is_function_impl<T> |
579 | {}; |
580 | |
581 | ////////////////////////////////////// |
582 | // is_union |
583 | ////////////////////////////////////// |
584 | template<class T> |
585 | struct is_union_noextents_cv |
586 | { static const bool value = BOOST_MOVE_IS_UNION_IMPL(T); }; |
587 | |
588 | template<class T> |
589 | struct is_union |
590 | : is_union_noextents_cv<typename remove_cv<typename remove_all_extents<T>::type>::type> |
591 | {}; |
592 | |
593 | ////////////////////////////////////// |
594 | // is_class |
595 | ////////////////////////////////////// |
596 | template <class T> |
597 | struct is_class |
598 | { |
599 | static const bool value = is_class_or_union<T>::value && ! is_union<T>::value; |
600 | }; |
601 | |
602 | |
603 | ////////////////////////////////////// |
604 | // is_arithmetic |
605 | ////////////////////////////////////// |
606 | template <class T> |
607 | struct is_arithmetic |
608 | { |
609 | static const bool value = is_floating_point<T>::value || |
610 | is_integral<T>::value; |
611 | }; |
612 | |
613 | ////////////////////////////////////// |
614 | // is_member_function_pointer |
615 | ////////////////////////////////////// |
616 | template <class T> |
617 | struct is_member_function_pointer_cv |
618 | { |
619 | static const bool value = false; |
620 | }; |
621 | |
622 | template <class T, class C> |
623 | struct is_member_function_pointer_cv<T C::*> |
624 | : is_function<T> |
625 | {}; |
626 | |
627 | template <class T> |
628 | struct is_member_function_pointer |
629 | : is_member_function_pointer_cv<typename remove_cv<T>::type> |
630 | {}; |
631 | |
632 | ////////////////////////////////////// |
633 | // is_enum |
634 | ////////////////////////////////////// |
635 | #if !defined(BOOST_MOVE_IS_ENUM) |
636 | //Based on (http://howardhinnant.github.io/TypeHiearchy.pdf) |
637 | template <class T> |
638 | struct is_enum_nonintrinsic |
639 | { |
640 | static const bool value = !is_arithmetic<T>::value && |
641 | !is_reference<T>::value && |
642 | !is_class_or_union<T>::value && |
643 | !is_array<T>::value && |
644 | !is_void<T>::value && |
645 | !is_nullptr_t<T>::value && |
646 | !is_member_pointer<T>::value && |
647 | !is_pointer<T>::value && |
648 | !is_function<T>::value; |
649 | }; |
650 | #endif |
651 | |
652 | template <class T> |
653 | struct is_enum |
654 | { static const bool value = BOOST_MOVE_IS_ENUM_IMPL(T); }; |
655 | |
656 | ////////////////////////////////////// |
657 | // is_pod |
658 | ////////////////////////////////////// |
659 | template<class T> |
660 | struct is_pod_noextents_cv //for non-c++11 compilers, a safe fallback |
661 | { static const bool value = BOOST_MOVE_IS_POD_IMPL(T); }; |
662 | |
663 | template<class T> |
664 | struct is_pod |
665 | : is_pod_noextents_cv<typename remove_cv<typename remove_all_extents<T>::type>::type> |
666 | {}; |
667 | |
668 | ////////////////////////////////////// |
669 | // is_empty |
670 | ////////////////////////////////////// |
671 | #if !defined(BOOST_MOVE_IS_EMPTY) |
672 | |
673 | template <typename T> |
674 | struct empty_helper_t1 : public T |
675 | { |
676 | empty_helper_t1(); // hh compiler bug workaround |
677 | int i[256]; |
678 | private: |
679 | |
680 | empty_helper_t1(const empty_helper_t1&); |
681 | empty_helper_t1& operator=(const empty_helper_t1&); |
682 | }; |
683 | |
684 | struct empty_helper_t2 { int i[256]; }; |
685 | |
686 | template <typename T, bool IsClass = is_class<T>::value > |
687 | struct is_empty_nonintrinsic |
688 | { |
689 | static const bool value = false; |
690 | }; |
691 | |
692 | template <typename T> |
693 | struct is_empty_nonintrinsic<T, true> |
694 | { |
695 | static const bool value = sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2); |
696 | }; |
697 | #endif |
698 | |
699 | template <class T> |
700 | struct is_empty |
701 | { static const bool value = BOOST_MOVE_IS_EMPTY_IMPL(T); }; |
702 | |
703 | ////////////////////////////////////// |
704 | // is_copy_constructible |
705 | ////////////////////////////////////// |
706 | template<class T> |
707 | struct is_copy_constructible |
708 | { |
709 | typedef char yes_type; |
710 | struct no_type { char dummy[2]; }; |
711 | template<class U> static typename add_reference<U>::type source(); |
712 | |
713 | // Intel compiler has problems with SFINAE for copy constructors and deleted functions: |
714 | // |
715 | // error: function *function_name* cannot be referenced -- it is a deleted function |
716 | // static yes_type test(U&, decltype(U(boost::declval<U&>()))* = 0); |
717 | // ^ |
718 | // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See: |
719 | // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken |
720 | #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION) &&\ |
721 | !(defined(BOOST_MSVC) && _MSC_VER == 1800) |
722 | static no_type test(...); |
723 | #ifdef BOOST_NO_CXX11_DECLTYPE |
724 | template <class U> |
725 | static yes_type test(U&, bool_<sizeof(U(source<U>()))>* = 0); |
726 | #else |
727 | template <class U> |
728 | static yes_type test(U&, decltype(U(source<U>()))* = 0); |
729 | #endif |
730 | #else |
731 | template <class U> |
732 | static no_type test(U&, typename U::boost_move_no_copy_constructor_or_assign* = 0); |
733 | static yes_type test(...); |
734 | #endif |
735 | |
736 | static const bool value = sizeof(test(source<T>())) == sizeof(yes_type); |
737 | }; |
738 | |
739 | ////////////////////////////////////// |
740 | // is_trivially_destructible |
741 | ////////////////////////////////////// |
742 | template<class T> |
743 | struct is_trivially_destructible |
744 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T); }; |
745 | |
746 | ////////////////////////////////////// |
747 | // is_trivially_default_constructible |
748 | ////////////////////////////////////// |
749 | template<class T> |
750 | struct is_trivially_default_constructible |
751 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T); }; |
752 | |
753 | ////////////////////////////////////// |
754 | // is_trivially_copy_constructible |
755 | ////////////////////////////////////// |
756 | template<class T> |
757 | struct is_trivially_copy_constructible |
758 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T); }; |
759 | |
760 | ////////////////////////////////////// |
761 | // is_trivially_move_constructible |
762 | ////////////////////////////////////// |
763 | template<class T> |
764 | struct is_trivially_move_constructible |
765 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T); }; |
766 | |
767 | ////////////////////////////////////// |
768 | // is_trivially_copy_assignable |
769 | ////////////////////////////////////// |
770 | template<class T> |
771 | struct is_trivially_copy_assignable |
772 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T); }; |
773 | |
774 | ////////////////////////////////////// |
775 | // is_trivially_move_assignable |
776 | ////////////////////////////////////// |
777 | template<class T> |
778 | struct is_trivially_move_assignable |
779 | { static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T); }; |
780 | |
781 | ////////////////////////////////////// |
782 | // is_nothrow_default_constructible |
783 | ////////////////////////////////////// |
784 | template<class T> |
785 | struct is_nothrow_default_constructible |
786 | : is_pod<T> |
787 | { static const bool value = BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T); }; |
788 | |
789 | ////////////////////////////////////// |
790 | // is_nothrow_copy_constructible |
791 | ////////////////////////////////////// |
792 | template<class T> |
793 | struct is_nothrow_copy_constructible |
794 | { static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T); }; |
795 | |
796 | ////////////////////////////////////// |
797 | // is_nothrow_move_constructible |
798 | ////////////////////////////////////// |
799 | template<class T> |
800 | struct is_nothrow_move_constructible |
801 | { static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T); }; |
802 | |
803 | ////////////////////////////////////// |
804 | // is_nothrow_copy_assignable |
805 | ////////////////////////////////////// |
806 | template<class T> |
807 | struct is_nothrow_copy_assignable |
808 | { static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T); }; |
809 | |
810 | ////////////////////////////////////// |
811 | // is_nothrow_move_assignable |
812 | ////////////////////////////////////// |
813 | template<class T> |
814 | struct is_nothrow_move_assignable |
815 | { static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T); }; |
816 | |
817 | ////////////////////////////////////// |
818 | // is_nothrow_swappable |
819 | ////////////////////////////////////// |
820 | template<class T> |
821 | struct is_nothrow_swappable |
822 | { |
823 | static const bool value = is_empty<T>::value || is_pod<T>::value; |
824 | }; |
825 | |
826 | ////////////////////////////////////// |
827 | // alignment_of |
828 | ////////////////////////////////////// |
829 | template <typename T> |
830 | struct alignment_of_hack |
831 | { |
832 | T t1; |
833 | char c; |
834 | T t2; |
835 | alignment_of_hack(); |
836 | }; |
837 | |
838 | template <unsigned A, unsigned S> |
839 | struct alignment_logic |
840 | { static const std::size_t value = A < S ? A : S; }; |
841 | |
842 | template< typename T > |
843 | struct alignment_of_impl |
844 | #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400) |
845 | // With MSVC both the native __alignof operator |
846 | // and our own logic gets things wrong from time to time :-( |
847 | // Using a combination of the two seems to make the most of a bad job: |
848 | : alignment_logic< sizeof(alignment_of_hack<T>) - 2*sizeof(T), __alignof(T)> |
849 | {}; |
850 | #elif !defined(BOOST_MOVE_ALIGNMENT_OF) |
851 | : alignment_logic< sizeof(alignment_of_hack<T>) - 2*sizeof(T), sizeof(T)> |
852 | {}; |
853 | #else |
854 | { static const std::size_t value = BOOST_MOVE_ALIGNMENT_OF(T); }; |
855 | #endif |
856 | |
857 | template< typename T > |
858 | struct alignment_of |
859 | : alignment_of_impl<T> |
860 | {}; |
861 | |
862 | class alignment_dummy; |
863 | typedef void (*function_ptr)(); |
864 | typedef int (alignment_dummy::*member_ptr); |
865 | typedef int (alignment_dummy::*member_function_ptr)(); |
866 | struct alignment_struct |
867 | { long double dummy[4]; }; |
868 | |
869 | ///////////////////////////// |
870 | // max_align_t |
871 | ///////////////////////////// |
872 | //This is not standard, but should work with all compilers |
873 | union max_align |
874 | { |
875 | char char_; |
876 | short short_; |
877 | int int_; |
878 | long long_; |
879 | #ifdef BOOST_HAS_LONG_LONG |
880 | ::boost::long_long_type long_long_; |
881 | #endif |
882 | float float_; |
883 | double double_; |
884 | void * void_ptr_; |
885 | long double long_double_[4]; |
886 | alignment_dummy *unknown_class_ptr_; |
887 | function_ptr function_ptr_; |
888 | member_function_ptr member_function_ptr_; |
889 | alignment_struct alignment_struct_; |
890 | }; |
891 | |
892 | typedef union max_align max_align_t; |
893 | |
894 | ///////////////////////////// |
895 | // aligned_storage |
896 | ///////////////////////////// |
897 | |
898 | #if !defined(BOOST_NO_ALIGNMENT) |
899 | |
900 | template<std::size_t Len, std::size_t Align> |
901 | struct aligned_storage_impl; |
902 | |
903 | #define BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(A)\ |
904 | template<std::size_t Len>\ |
905 | struct BOOST_ALIGNMENT(A) aligned_storage_impl<Len, A>\ |
906 | {\ |
907 | char dummy[Len];\ |
908 | typedef aligned_storage_impl<Len, A> type;\ |
909 | };\ |
910 | // |
911 | |
912 | //Up to 4K alignment (typical page size) |
913 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1) |
914 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x2) |
915 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x4) |
916 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x8) |
917 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x10) |
918 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x20) |
919 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x40) |
920 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x80) |
921 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100) |
922 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200) |
923 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400) |
924 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800) |
925 | BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000) |
926 | |
927 | #undef BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT |
928 | |
929 | #else //BOOST_NO_ALIGNMENT |
930 | |
931 | template<class T, size_t Len> |
932 | union aligned_union |
933 | { |
934 | T aligner; |
935 | char dummy[Len]; |
936 | }; |
937 | |
938 | template<std::size_t Len, std::size_t Align, class T, bool Ok> |
939 | struct aligned_next; |
940 | |
941 | template<std::size_t Len, std::size_t Align, class T> |
942 | struct aligned_next<Len, Align, T, true> |
943 | { |
944 | BOOST_STATIC_ASSERT((alignment_of<T>::value == Align)); |
945 | typedef aligned_union<T, Len> type; |
946 | }; |
947 | |
948 | //End of search defaults to max_align_t |
949 | template<std::size_t Len, std::size_t Align> |
950 | struct aligned_next<Len, Align, max_align_t, false> |
951 | { typedef aligned_union<max_align_t, Len> type; }; |
952 | |
953 | //Now define a search list through types |
954 | #define BOOST_MOVE_ALIGNED_NEXT_STEP(TYPE, NEXT_TYPE)\ |
955 | template<std::size_t Len, std::size_t Align>\ |
956 | struct aligned_next<Len, Align, TYPE, false>\ |
957 | : aligned_next<Len, Align, NEXT_TYPE, Align == alignment_of<NEXT_TYPE>::value>\ |
958 | {};\ |
959 | // |
960 | BOOST_MOVE_ALIGNED_NEXT_STEP(long double, max_align_t) |
961 | BOOST_MOVE_ALIGNED_NEXT_STEP(double, long double) |
962 | #ifdef BOOST_HAS_LONG_LONG |
963 | BOOST_MOVE_ALIGNED_NEXT_STEP(::boost::long_long_type, double) |
964 | BOOST_MOVE_ALIGNED_NEXT_STEP(long, ::boost::long_long_type) |
965 | #else |
966 | BOOST_MOVE_ALIGNED_NEXT_STEP(long, double) |
967 | #endif |
968 | BOOST_MOVE_ALIGNED_NEXT_STEP(int, long) |
969 | BOOST_MOVE_ALIGNED_NEXT_STEP(short, int) |
970 | BOOST_MOVE_ALIGNED_NEXT_STEP(char, short) |
971 | #undef BOOST_MOVE_ALIGNED_NEXT_STEP |
972 | |
973 | template<std::size_t Len, std::size_t Align> |
974 | struct aligned_storage_impl |
975 | : aligned_next<Len, Align, char, Align == alignment_of<char>::value> |
976 | {}; |
977 | |
978 | #endif |
979 | |
980 | template<std::size_t Len, std::size_t Align = alignment_of<max_align_t>::value> |
981 | struct aligned_storage |
982 | { |
983 | //Sanity checks for input parameters |
984 | BOOST_STATIC_ASSERT(Align > 0); |
985 | |
986 | //Sanity checks for output type |
987 | typedef typename aligned_storage_impl<Len ? Len : 1, Align>::type type; |
988 | static const std::size_t value = alignment_of<type>::value; |
989 | BOOST_STATIC_ASSERT(value >= Align); |
990 | BOOST_STATIC_ASSERT((value % Align) == 0); |
991 | |
992 | //Just in case someone instantiates aligned_storage |
993 | //instead of aligned_storage::type (typical error). |
994 | private: |
995 | aligned_storage(); |
996 | }; |
997 | |
998 | } //namespace move_detail { |
999 | } //namespace boost { |
1000 | |
1001 | #include <boost/move/detail/config_end.hpp> |
1002 | |
1003 | #endif //#ifndef BOOST_MOVE_DETAIL_TYPE_TRAITS_HPP |
1004 | |