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
312namespace boost {
313namespace move_detail {
314
315//////////////////////////
316// is_reference
317//////////////////////////
318template<class T>
319struct is_reference
320{ static const bool value = false; };
321
322template<class T>
323struct is_reference<T&>
324{ static const bool value = true; };
325
326#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
327template<class T>
328struct is_reference<T&&>
329{ static const bool value = true; };
330#endif
331
332//////////////////////////
333// is_pointer
334//////////////////////////
335template<class T>
336struct is_pointer
337{ static const bool value = false; };
338
339template<class T>
340struct is_pointer<T*>
341{ static const bool value = true; };
342
343//////////////////////////
344// add_reference
345//////////////////////////
346template <typename T>
347struct add_reference
348{ typedef T& type; };
349
350template<class T>
351struct add_reference<T&>
352{ typedef T& type; };
353
354template<>
355struct add_reference<void>
356{ typedef nat &type; };
357
358template<>
359struct add_reference<const void>
360{ typedef const nat &type; };
361
362//////////////////////////
363// add_const_reference
364//////////////////////////
365template <class T>
366struct add_const_reference
367{ typedef const T &type; };
368
369template <class T>
370struct add_const_reference<T&>
371{ typedef T& type; };
372
373//////////////////////////
374// remove_const
375//////////////////////////
376template<class T>
377struct remove_const
378{ typedef T type; };
379
380template<class T>
381struct remove_const< const T>
382{ typedef T type; };
383
384//////////////////////////
385// remove_cv
386//////////////////////////
387template<typename T> struct remove_cv { typedef T type; };
388template<typename T> struct remove_cv<const T> { typedef T type; };
389template<typename T> struct remove_cv<const volatile T> { typedef T type; };
390template<typename T> struct remove_cv<volatile T> { typedef T type; };
391
392//////////////////////////
393// make_unsigned
394//////////////////////////
395template <class T>
396struct make_unsigned_impl { typedef T type; };
397template <> struct make_unsigned_impl<signed char> { typedef unsigned char type; };
398template <> struct make_unsigned_impl<signed short> { typedef unsigned short type; };
399template <> struct make_unsigned_impl<signed int> { typedef unsigned int type; };
400template <> struct make_unsigned_impl<signed long> { typedef unsigned long type; };
401#ifdef BOOST_HAS_LONG_LONG
402template <> struct make_unsigned_impl< ::boost::long_long_type > { typedef ::boost::ulong_long_type type; };
403#endif
404
405template <class T>
406struct make_unsigned
407 : make_unsigned_impl<typename remove_cv<T>::type>
408{};
409
410//////////////////////////
411// is_floating_point
412//////////////////////////
413template<class T> struct is_floating_point_cv { static const bool value = false; };
414template<> struct is_floating_point_cv<float> { static const bool value = true; };
415template<> struct is_floating_point_cv<double> { static const bool value = true; };
416template<> struct is_floating_point_cv<long double> { static const bool value = true; };
417
418template<class T>
419struct is_floating_point
420 : is_floating_point_cv<typename remove_cv<T>::type>
421{};
422
423//////////////////////////
424// is_integral
425//////////////////////////
426template<class T> struct is_integral_cv { static const bool value = false; };
427template<> struct is_integral_cv< bool>{ static const bool value = true; };
428template<> struct is_integral_cv< char>{ static const bool value = true; };
429template<> struct is_integral_cv< unsigned char>{ static const bool value = true; };
430template<> struct is_integral_cv< signed char>{ static const bool value = true; };
431#ifndef BOOST_NO_CXX11_CHAR16_T
432template<> struct is_integral_cv< char16_t>{ static const bool value = true; };
433#endif
434#ifndef BOOST_NO_CXX11_CHAR32_T
435template<> struct is_integral_cv< char32_t>{ static const bool value = true; };
436#endif
437#ifndef BOOST_NO_INTRINSIC_WCHAR_T
438template<> struct is_integral_cv< wchar_t>{ static const bool value = true; };
439#endif
440template<> struct is_integral_cv< short>{ static const bool value = true; };
441template<> struct is_integral_cv< unsigned short>{ static const bool value = true; };
442template<> struct is_integral_cv< int>{ static const bool value = true; };
443template<> struct is_integral_cv< unsigned int>{ static const bool value = true; };
444template<> struct is_integral_cv< long>{ static const bool value = true; };
445template<> struct is_integral_cv< unsigned long>{ static const bool value = true; };
446#ifdef BOOST_HAS_LONG_LONG
447template<> struct is_integral_cv< ::boost:: long_long_type>{ static const bool value = true; };
448template<> struct is_integral_cv< ::boost::ulong_long_type>{ static const bool value = true; };
449#endif
450
451template<class T>
452struct is_integral
453 : public is_integral_cv<typename remove_cv<T>::type>
454{};
455
456//////////////////////////////////////
457// remove_all_extents
458//////////////////////////////////////
459template <class T>
460struct remove_all_extents
461{ typedef T type;};
462
463template <class T>
464struct remove_all_extents<T[]>
465{ typedef typename remove_all_extents<T>::type type; };
466
467template <class T, size_t N>
468struct remove_all_extents<T[N]>
469{ typedef typename remove_all_extents<T>::type type;};
470
471//////////////////////////
472// is_scalar
473//////////////////////////
474template<class T>
475struct is_scalar
476{ static const bool value = is_integral<T>::value || is_floating_point<T>::value; };
477
478//////////////////////////
479// is_void
480//////////////////////////
481template<class T>
482struct is_void_cv
483{ static const bool value = false; };
484
485template<>
486struct is_void_cv<void>
487{ static const bool value = true; };
488
489template<class T>
490struct is_void
491 : is_void_cv<typename remove_cv<T>::type>
492{};
493
494//////////////////////////////////////
495// is_array
496//////////////////////////////////////
497template<class T>
498struct is_array
499{ static const bool value = false; };
500
501template<class T>
502struct is_array<T[]>
503{ static const bool value = true; };
504
505template<class T, std::size_t N>
506struct is_array<T[N]>
507{ static const bool value = true; };
508
509//////////////////////////////////////
510// is_member_pointer
511//////////////////////////////////////
512template <class T> struct is_member_pointer_cv { static const bool value = false; };
513template <class T, class U>struct is_member_pointer_cv<T U::*> { static const bool value = true; };
514
515template <class T>
516struct is_member_pointer
517 : is_member_pointer_cv<typename remove_cv<T>::type>
518{};
519
520//////////////////////////////////////
521// is_nullptr_t
522//////////////////////////////////////
523template <class T>
524struct is_nullptr_t_cv
525{ static const bool value = false; };
526
527#if !defined(BOOST_NO_CXX11_NULLPTR)
528template <>
529struct 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
538template <class T>
539struct 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.
550template <class T>
551struct 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)
564template < 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 >
569struct is_function_impl
570{ static const bool value = is_reference_convertible_to_pointer<T>::value; };
571
572template <class T>
573struct is_function_impl<T, true>
574{ static const bool value = false; };
575
576template <class T>
577struct is_function
578 : is_function_impl<T>
579{};
580
581//////////////////////////////////////
582// is_union
583//////////////////////////////////////
584template<class T>
585struct is_union_noextents_cv
586{ static const bool value = BOOST_MOVE_IS_UNION_IMPL(T); };
587
588template<class T>
589struct is_union
590 : is_union_noextents_cv<typename remove_cv<typename remove_all_extents<T>::type>::type>
591{};
592
593//////////////////////////////////////
594// is_class
595//////////////////////////////////////
596template <class T>
597struct 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//////////////////////////////////////
606template <class T>
607struct 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//////////////////////////////////////
616template <class T>
617struct is_member_function_pointer_cv
618{
619 static const bool value = false;
620};
621
622template <class T, class C>
623struct is_member_function_pointer_cv<T C::*>
624 : is_function<T>
625{};
626
627template <class T>
628struct 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)
637template <class T>
638struct 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
652template <class T>
653struct is_enum
654{ static const bool value = BOOST_MOVE_IS_ENUM_IMPL(T); };
655
656//////////////////////////////////////
657// is_pod
658//////////////////////////////////////
659template<class T>
660struct is_pod_noextents_cv //for non-c++11 compilers, a safe fallback
661{ static const bool value = BOOST_MOVE_IS_POD_IMPL(T); };
662
663template<class T>
664struct 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
673template <typename T>
674struct 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
684struct empty_helper_t2 { int i[256]; };
685
686template <typename T, bool IsClass = is_class<T>::value >
687struct is_empty_nonintrinsic
688{
689 static const bool value = false;
690};
691
692template <typename T>
693struct is_empty_nonintrinsic<T, true>
694{
695 static const bool value = sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2);
696};
697#endif
698
699template <class T>
700struct is_empty
701{ static const bool value = BOOST_MOVE_IS_EMPTY_IMPL(T); };
702
703//////////////////////////////////////
704// is_copy_constructible
705//////////////////////////////////////
706template<class T>
707struct 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//////////////////////////////////////
742template<class T>
743struct is_trivially_destructible
744{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T); };
745
746//////////////////////////////////////
747// is_trivially_default_constructible
748//////////////////////////////////////
749template<class T>
750struct is_trivially_default_constructible
751{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T); };
752
753//////////////////////////////////////
754// is_trivially_copy_constructible
755//////////////////////////////////////
756template<class T>
757struct is_trivially_copy_constructible
758{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T); };
759
760//////////////////////////////////////
761// is_trivially_move_constructible
762//////////////////////////////////////
763template<class T>
764struct is_trivially_move_constructible
765{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T); };
766
767//////////////////////////////////////
768// is_trivially_copy_assignable
769//////////////////////////////////////
770template<class T>
771struct is_trivially_copy_assignable
772{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T); };
773
774//////////////////////////////////////
775// is_trivially_move_assignable
776//////////////////////////////////////
777template<class T>
778struct is_trivially_move_assignable
779{ static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T); };
780
781//////////////////////////////////////
782// is_nothrow_default_constructible
783//////////////////////////////////////
784template<class T>
785struct 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//////////////////////////////////////
792template<class T>
793struct is_nothrow_copy_constructible
794{ static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T); };
795
796//////////////////////////////////////
797// is_nothrow_move_constructible
798//////////////////////////////////////
799template<class T>
800struct is_nothrow_move_constructible
801{ static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T); };
802
803//////////////////////////////////////
804// is_nothrow_copy_assignable
805//////////////////////////////////////
806template<class T>
807struct is_nothrow_copy_assignable
808{ static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T); };
809
810//////////////////////////////////////
811// is_nothrow_move_assignable
812//////////////////////////////////////
813template<class T>
814struct is_nothrow_move_assignable
815{ static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T); };
816
817//////////////////////////////////////
818// is_nothrow_swappable
819//////////////////////////////////////
820template<class T>
821struct is_nothrow_swappable
822{
823 static const bool value = is_empty<T>::value || is_pod<T>::value;
824};
825
826//////////////////////////////////////
827// alignment_of
828//////////////////////////////////////
829template <typename T>
830struct alignment_of_hack
831{
832 T t1;
833 char c;
834 T t2;
835 alignment_of_hack();
836};
837
838template <unsigned A, unsigned S>
839struct alignment_logic
840{ static const std::size_t value = A < S ? A : S; };
841
842template< typename T >
843struct 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
857template< typename T >
858struct alignment_of
859 : alignment_of_impl<T>
860{};
861
862class alignment_dummy;
863typedef void (*function_ptr)();
864typedef int (alignment_dummy::*member_ptr);
865typedef int (alignment_dummy::*member_function_ptr)();
866struct 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
873union 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
892typedef union max_align max_align_t;
893
894/////////////////////////////
895// aligned_storage
896/////////////////////////////
897
898#if !defined(BOOST_NO_ALIGNMENT)
899
900template<std::size_t Len, std::size_t Align>
901struct aligned_storage_impl;
902
903#define BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(A)\
904template<std::size_t Len>\
905struct 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)
913BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1)
914BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x2)
915BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x4)
916BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x8)
917BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x10)
918BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x20)
919BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x40)
920BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x80)
921BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100)
922BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200)
923BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400)
924BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800)
925BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)
926
927#undef BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT
928
929#else //BOOST_NO_ALIGNMENT
930
931template<class T, size_t Len>
932union aligned_union
933{
934 T aligner;
935 char dummy[Len];
936};
937
938template<std::size_t Len, std::size_t Align, class T, bool Ok>
939struct aligned_next;
940
941template<std::size_t Len, std::size_t Align, class T>
942struct 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
949template<std::size_t Len, std::size_t Align>
950struct 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
973template<std::size_t Len, std::size_t Align>
974struct aligned_storage_impl
975 : aligned_next<Len, Align, char, Align == alignment_of<char>::value>
976{};
977
978#endif
979
980template<std::size_t Len, std::size_t Align = alignment_of<max_align_t>::value>
981struct 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