1 //////////////////////////////////////////////////////////////////////////////
2 // (C) Copyright John Maddock 2000.
3 // (C) Copyright Ion Gaztanaga 2005-2015.
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)
9 // See http://www.boost.org/libs/move for documentation.
11 // The alignment and Type traits implementation comes from
12 // John Maddock's TypeTraits library.
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
19 #ifndef BOOST_CONFIG_HPP
20 # include <boost/config.hpp>
23 #if defined(BOOST_HAS_PRAGMA_ONCE)
27 #include <boost/move/detail/config_begin.hpp>
28 #include <boost/move/detail/workaround.hpp>
31 #include <boost/move/detail/meta_utils.hpp>
33 #include <boost/assert.hpp>
34 #include <boost/static_assert.hpp>
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.
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
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:
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 // (Note: this trait does not guarantee T is copy constructible, the copy constructor could be deleted but still be trivial)
59 // BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) should evaluate to true if T(boost::move(t)) <==> memcpy
60 // BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) should evaluate to true if t = u <==> memcpy
61 // (Note: this trait does not guarantee T is assignable , the copy assignmen could be deleted but still be trivial)
62 // BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) should evaluate to true if t = boost::move(u) <==> memcpy
63 // BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) should evaluate to true if ~T() has no effect
64 // BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) should evaluate to true if "T x;" can not throw
65 // BOOST_MOVE_HAS_NOTHROW_COPY(T) should evaluate to true if T(t) can not throw
66 // BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) should evaluate to true if t = u can not throw
67 // BOOST_MOVE_IS_ENUM(T) should evaluate to true it t is a union type.
69 // The following can also be defined: when detected our implementation is greatly simplified.
71 // BOOST_ALIGNMENT_OF(T) should evaluate to the alignment requirements of type T.
73 #if defined(__MSL_CPP__) && (__MSL_CPP__ >= 0x8000)
74 // Metrowerks compiler is acquiring intrinsic type traits support
75 // post version 8. We hook into the published interface to pick up
76 // user defined specializations as well as compiler intrinsics as
77 // and when they become available:
78 # include <msl_utility>
79 # define BOOST_MOVE_IS_UNION(T) BOOST_STD_EXTENSION_NAMESPACE::is_union<T>::value
80 # define BOOST_MOVE_IS_POD(T) BOOST_STD_EXTENSION_NAMESPACE::is_POD<T>::value
81 # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_default_ctor<T>::value
82 # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_copy_ctor<T>::value
83 # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_assignment<T>::value
84 # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_dtor<T>::value
87 #if (defined(BOOST_MSVC) && defined(BOOST_MSVC_FULL_VER) && (BOOST_MSVC_FULL_VER >=140050215))\
88 || (defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1500))
89 # define BOOST_MOVE_IS_UNION(T) __is_union(T)
90 # define BOOST_MOVE_IS_POD(T) (__is_pod(T) && __has_trivial_constructor(T))
91 # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T)
92 # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T)
93 # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T)|| ::boost::move_detail::is_pod<T>::value)
94 # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) || ::boost::move_detail::is_pod<T>::value)
95 # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) || ::boost::move_detail::is_pod<T>::value)
96 # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) || ::boost::move_detail::is_trivially_default_constructible<T>::value)
97 # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T) || ::boost::move_detail::is_trivially_copy_constructible<T>::value)
98 # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) || ::boost::move_detail::is_trivially_copy_assignable<T>::value)
100 # define BOOST_MOVE_IS_ENUM(T) __is_enum(T)
101 # if defined(_MSC_VER) && (_MSC_VER >= 1700)
102 # define BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__has_trivial_move_constructor(T) || ::boost::move_detail::is_pod<T>::value)
103 # define BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) (__has_trivial_move_assign(T) || ::boost::move_detail::is_pod<T>::value)
107 #if defined(BOOST_CLANG) && defined(__has_feature)
109 # if __has_feature(is_union)
110 # define BOOST_MOVE_IS_UNION(T) __is_union(T)
112 # if (!defined(__GLIBCXX__) || (__GLIBCXX__ >= 20080306 && __GLIBCXX__ != 20080519)) && __has_feature(is_pod)
113 # define BOOST_MOVE_IS_POD(T) __is_pod(T)
115 # if (!defined(__GLIBCXX__) || (__GLIBCXX__ >= 20080306 && __GLIBCXX__ != 20080519)) && __has_feature(is_empty)
116 # define BOOST_MOVE_IS_EMPTY(T) __is_empty(T)
118 # if __has_feature(has_trivial_constructor)
119 # define BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T)
121 # if __has_feature(has_trivial_copy)
122 # define BOOST_MOVE_HAS_TRIVIAL_COPY(T) __has_trivial_copy(T)
124 # if __has_feature(has_trivial_assign)
125 # define BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) )
127 # if __has_feature(has_trivial_destructor)
128 # define BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
130 # if __has_feature(has_nothrow_constructor)
131 # define BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T) __has_nothrow_constructor(T)
133 # if __has_feature(has_nothrow_copy)
134 # define BOOST_MOVE_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T))
136 # if __has_feature(is_nothrow_copy_assignable)
137 # define BOOST_MOVE_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T))
139 # if __has_feature(is_enum)
140 # define BOOST_MOVE_IS_ENUM(T) __is_enum(T)
142 # if __has_feature(has_trivial_move_constructor)
143 # define BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) __has_trivial_move_constructor(T)
145 # if __has_feature(has_trivial_move_assign)
146 # define BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T) __has_trivial_move_assign(T)
148 # define BOOST_MOVE_ALIGNMENT_OF(T) __alignof(T)
151 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) && !defined(__GCCXML__))) && !defined(BOOST_CLANG)
154 # define BOOST_MOVE_INTEL_TT_OPTS || ::boost::move_detail::is_pod<T>::value
156 # define BOOST_MOVE_INTEL_TT_OPTS
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))
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)
179 #if defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
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))
192 # define BOOST_MOVE_IS_ENUM(T) __is_enum(T)
193 # define BOOST_MOVE_ALIGNMENT_OF(T) __alignof__(T)
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))
208 # define BOOST_MOVE_IS_ENUM(T) __is_enum(T)
209 # define BOOST_MOVE_ALIGNMENT_OF(T) alignof(T)
213 //Fallback definitions
215 #ifdef BOOST_MOVE_IS_UNION
216 #define BOOST_MOVE_IS_UNION_IMPL(T) BOOST_MOVE_IS_UNION(T)
218 #define BOOST_MOVE_IS_UNION_IMPL(T) false
221 #ifdef BOOST_MOVE_IS_POD
222 //in some compilers the intrinsic is limited to class types so add scalar and void
223 #define BOOST_MOVE_IS_POD_IMPL(T) (::boost::move_detail::is_scalar<T>::value ||\
224 ::boost::move_detail::is_void<T>::value ||\
225 BOOST_MOVE_IS_POD(T))
227 #define BOOST_MOVE_IS_POD_IMPL(T) \
228 (::boost::move_detail::is_scalar<T>::value || ::boost::move_detail::is_void<T>::value)
231 #ifdef BOOST_MOVE_IS_EMPTY
232 #define BOOST_MOVE_IS_EMPTY_IMPL(T) BOOST_MOVE_IS_EMPTY(T)
234 #define BOOST_MOVE_IS_EMPTY_IMPL(T) ::boost::move_detail::is_empty_nonintrinsic<T>::value
237 #ifdef BOOST_MOVE_HAS_TRIVIAL_COPY
238 #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value ||\
239 (::boost::move_detail::is_copy_constructible<T>::value &&\
240 BOOST_MOVE_HAS_TRIVIAL_COPY(T))
242 #define BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
245 #ifdef BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR
246 #define BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_CONSTRUCTOR(T)
248 #define BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
251 #ifdef BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR
252 #define BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T)
254 #define BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
257 #ifdef BOOST_MOVE_HAS_TRIVIAL_ASSIGN
258 #define BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value ||\
259 ( ::boost::move_detail::is_copy_assignable<T>::value &&\
260 BOOST_MOVE_HAS_TRIVIAL_ASSIGN(T))
262 #define BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value
265 #ifdef BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN
266 #define BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T) BOOST_MOVE_HAS_TRIVIAL_MOVE_ASSIGN(T)
268 #define BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value
271 #ifdef BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR
272 #define BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T) BOOST_MOVE_HAS_TRIVIAL_DESTRUCTOR(T)
274 #define BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
277 #ifdef BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR
278 #define BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_CONSTRUCTOR(T)
280 #define BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
283 #ifdef BOOST_MOVE_HAS_NOTHROW_COPY
284 #define BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_COPY(T)
286 #define BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
289 #ifdef BOOST_MOVE_HAS_NOTHROW_MOVE
290 #define BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T) BOOST_MOVE_HAS_NOTHROW_MOVE(T)
292 #define BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T) ::boost::move_detail::is_pod<T>::value
295 #ifdef BOOST_MOVE_HAS_NOTHROW_ASSIGN
296 #define BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T) BOOST_MOVE_HAS_NOTHROW_ASSIGN(T)
298 #define BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value
301 #ifdef BOOST_MOVE_HAS_NOTHROW_MOVE_ASSIGN
302 #define BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T) BOOST_MOVE_HAS_NOTHROW_MOVE_ASSIGN(T)
304 #define BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T) ::boost::move_detail::is_pod<T>::value
307 #ifdef BOOST_MOVE_IS_ENUM
308 #define BOOST_MOVE_IS_ENUM_IMPL(T) BOOST_MOVE_IS_ENUM(T)
310 #define BOOST_MOVE_IS_ENUM_IMPL(T) ::boost::move_detail::is_enum_nonintrinsic<T>::value
314 namespace move_detail {
316 //////////////////////////
318 //////////////////////////
321 { static const bool value = false; };
324 struct is_reference<T&>
325 { static const bool value = true; };
327 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
329 struct is_reference<T&&>
330 { static const bool value = true; };
333 //////////////////////////
335 //////////////////////////
338 { static const bool value = false; };
341 struct is_pointer<T*>
342 { static const bool value = true; };
344 //////////////////////////
346 //////////////////////////
349 { static const bool value = false; };
352 struct is_const<const T>
353 { static const bool value = true; };
355 //////////////////////////
357 //////////////////////////
358 template <typename T> struct unvoid_ref : add_lvalue_reference<T>{};
359 template <> struct unvoid_ref<void> { typedef unvoid_ref & type; };
360 template <> struct unvoid_ref<const void> { typedef unvoid_ref & type; };
361 template <> struct unvoid_ref<volatile void> { typedef unvoid_ref & type; };
362 template <> struct unvoid_ref<const volatile void> { typedef unvoid_ref & type; };
364 template <typename T>
365 struct add_reference : add_lvalue_reference<T>
368 //////////////////////////
369 // add_const_reference
370 //////////////////////////
372 struct add_const_reference
373 { typedef const T &type; };
376 struct add_const_reference<T&>
377 { typedef T& type; };
379 //////////////////////////
381 //////////////////////////
382 template<class T, bool Add>
383 struct add_const_if_c
384 : if_c<Add, typename add_const<T>::type, T>
387 //////////////////////////
389 //////////////////////////
395 struct remove_const< const T>
398 //////////////////////////
400 //////////////////////////
401 template<typename T> struct remove_cv { typedef T type; };
402 template<typename T> struct remove_cv<const T> { typedef T type; };
403 template<typename T> struct remove_cv<const volatile T> { typedef T type; };
404 template<typename T> struct remove_cv<volatile T> { typedef T type; };
406 //////////////////////////
408 //////////////////////////
410 struct make_unsigned_impl { typedef T type; };
411 template <> struct make_unsigned_impl<signed char> { typedef unsigned char type; };
412 template <> struct make_unsigned_impl<signed short> { typedef unsigned short type; };
413 template <> struct make_unsigned_impl<signed int> { typedef unsigned int type; };
414 template <> struct make_unsigned_impl<signed long> { typedef unsigned long type; };
415 #ifdef BOOST_HAS_LONG_LONG
416 template <> struct make_unsigned_impl< ::boost::long_long_type > { typedef ::boost::ulong_long_type type; };
421 : make_unsigned_impl<typename remove_cv<T>::type>
424 //////////////////////////
426 //////////////////////////
427 template<class T> struct is_floating_point_cv { static const bool value = false; };
428 template<> struct is_floating_point_cv<float> { static const bool value = true; };
429 template<> struct is_floating_point_cv<double> { static const bool value = true; };
430 template<> struct is_floating_point_cv<long double> { static const bool value = true; };
433 struct is_floating_point
434 : is_floating_point_cv<typename remove_cv<T>::type>
437 //////////////////////////
439 //////////////////////////
440 template<class T> struct is_integral_cv { static const bool value = false; };
441 template<> struct is_integral_cv< bool>{ static const bool value = true; };
442 template<> struct is_integral_cv< char>{ static const bool value = true; };
443 template<> struct is_integral_cv< unsigned char>{ static const bool value = true; };
444 template<> struct is_integral_cv< signed char>{ static const bool value = true; };
445 #ifndef BOOST_NO_CXX11_CHAR16_T
446 template<> struct is_integral_cv< char16_t>{ static const bool value = true; };
448 #ifndef BOOST_NO_CXX11_CHAR32_T
449 template<> struct is_integral_cv< char32_t>{ static const bool value = true; };
451 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
452 template<> struct is_integral_cv< wchar_t>{ static const bool value = true; };
454 template<> struct is_integral_cv< short>{ static const bool value = true; };
455 template<> struct is_integral_cv< unsigned short>{ static const bool value = true; };
456 template<> struct is_integral_cv< int>{ static const bool value = true; };
457 template<> struct is_integral_cv< unsigned int>{ static const bool value = true; };
458 template<> struct is_integral_cv< long>{ static const bool value = true; };
459 template<> struct is_integral_cv< unsigned long>{ static const bool value = true; };
460 #ifdef BOOST_HAS_LONG_LONG
461 template<> struct is_integral_cv< ::boost:: long_long_type>{ static const bool value = true; };
462 template<> struct is_integral_cv< ::boost::ulong_long_type>{ static const bool value = true; };
467 : public is_integral_cv<typename remove_cv<T>::type>
470 //////////////////////////////////////
471 // remove_all_extents
472 //////////////////////////////////////
474 struct remove_all_extents
478 struct remove_all_extents<T[]>
479 { typedef typename remove_all_extents<T>::type type; };
481 template <class T, std::size_t N>
482 struct remove_all_extents<T[N]>
483 { typedef typename remove_all_extents<T>::type type;};
485 //////////////////////////
487 //////////////////////////
490 { static const bool value = is_integral<T>::value || is_floating_point<T>::value; };
492 //////////////////////////
494 //////////////////////////
497 { static const bool value = false; };
500 struct is_void_cv<void>
501 { static const bool value = true; };
505 : is_void_cv<typename remove_cv<T>::type>
508 //////////////////////////////////////
510 //////////////////////////////////////
513 { static const bool value = false; };
517 { static const bool value = true; };
519 template<class T, std::size_t N>
520 struct is_array<T[N]>
521 { static const bool value = true; };
523 //////////////////////////////////////
525 //////////////////////////////////////
526 template <class T> struct is_member_pointer_cv { static const bool value = false; };
527 template <class T, class U>struct is_member_pointer_cv<T U::*> { static const bool value = true; };
530 struct is_member_pointer
531 : is_member_pointer_cv<typename remove_cv<T>::type>
534 //////////////////////////////////////
536 //////////////////////////////////////
538 struct is_nullptr_t_cv
539 { static const bool value = false; };
541 #if !defined(BOOST_NO_CXX11_NULLPTR)
543 struct is_nullptr_t_cv
544 #if !defined(BOOST_NO_CXX11_DECLTYPE)
549 { static const bool value = true; };
554 : is_nullptr_t_cv<typename remove_cv<T>::type>
557 //////////////////////////////////////
559 //////////////////////////////////////
560 //Inspired by libc++, thanks to Howard Hinnant
561 //For a function to pointer an lvalue of function type T can be implicitly converted to a prvalue
562 //pointer to that function. This does not apply to non-static member functions because lvalues
563 //that refer to non-static member functions do not exist.
565 struct is_reference_convertible_to_pointer
567 struct twochar { char dummy[2]; };
568 template <class U> static char test(U*);
569 template <class U> static twochar test(...);
571 static const bool value = sizeof(char) == sizeof(test<T>(source()));
574 // - class types that might have implicit conversions
575 // - void (to avoid forming a reference to void later)
576 // - references (e.g.: filtering reference to functions)
577 // - nullptr_t (convertible to pointer)
579 , bool Filter = is_class_or_union<T>::value ||
581 is_reference<T>::value ||
582 is_nullptr_t<T>::value >
583 struct is_function_impl
584 { static const bool value = is_reference_convertible_to_pointer<T>::value; };
587 struct is_function_impl<T, true>
588 { static const bool value = false; };
592 : is_function_impl<T>
595 //////////////////////////////////////
597 //////////////////////////////////////
599 struct is_union_noextents_cv
600 { static const bool value = BOOST_MOVE_IS_UNION_IMPL(T); };
604 : is_union_noextents_cv<typename remove_cv<typename remove_all_extents<T>::type>::type>
607 //////////////////////////////////////
609 //////////////////////////////////////
613 static const bool value = is_class_or_union<T>::value && ! is_union<T>::value;
617 //////////////////////////////////////
619 //////////////////////////////////////
623 static const bool value = is_floating_point<T>::value ||
624 is_integral<T>::value;
627 //////////////////////////////////////
628 // is_member_function_pointer
629 //////////////////////////////////////
631 struct is_member_function_pointer_cv
633 static const bool value = false;
636 template <class T, class C>
637 struct is_member_function_pointer_cv<T C::*>
642 struct is_member_function_pointer
643 : is_member_function_pointer_cv<typename remove_cv<T>::type>
646 //////////////////////////////////////
648 //////////////////////////////////////
649 #if !defined(BOOST_MOVE_IS_ENUM)
650 //Based on (http://howardhinnant.github.io/TypeHiearchy.pdf)
652 struct is_enum_nonintrinsic
654 static const bool value = !is_arithmetic<T>::value &&
655 !is_reference<T>::value &&
656 !is_class_or_union<T>::value &&
657 !is_array<T>::value &&
658 !is_void<T>::value &&
659 !is_nullptr_t<T>::value &&
660 !is_member_pointer<T>::value &&
661 !is_pointer<T>::value &&
662 !is_function<T>::value;
668 { static const bool value = BOOST_MOVE_IS_ENUM_IMPL(T); };
670 //////////////////////////////////////
672 //////////////////////////////////////
674 struct is_pod_noextents_cv //for non-c++11 compilers, a safe fallback
675 { static const bool value = BOOST_MOVE_IS_POD_IMPL(T); };
679 : is_pod_noextents_cv<typename remove_cv<typename remove_all_extents<T>::type>::type>
682 //////////////////////////////////////
684 //////////////////////////////////////
685 #if !defined(BOOST_MOVE_IS_EMPTY)
687 template <typename T>
688 struct empty_helper_t1 : public T
690 empty_helper_t1(); // hh compiler bug workaround
694 empty_helper_t1(const empty_helper_t1&);
695 empty_helper_t1& operator=(const empty_helper_t1&);
698 struct empty_helper_t2 { int i[256]; };
700 template <typename T, bool IsClass = is_class<T>::value >
701 struct is_empty_nonintrinsic
703 static const bool value = false;
706 template <typename T>
707 struct is_empty_nonintrinsic<T, true>
709 static const bool value = sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2);
715 { static const bool value = BOOST_MOVE_IS_EMPTY_IMPL(T); };
719 struct has_boost_move_no_copy_constructor_or_assign_type
722 static yes_type test(typename U::boost_move_no_copy_constructor_or_assign*);
725 static no_type test(...);
727 static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
730 //////////////////////////////////////
731 // is_copy_constructible
732 //////////////////////////////////////
733 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_NO_CXX11_DECLTYPE) \
734 && !defined(BOOST_INTEL_CXX_VERSION) && \
735 !(defined(BOOST_MSVC) && _MSC_VER == 1800)
736 #define BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE
740 struct is_copy_constructible
742 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
744 // error: function *function_name* cannot be referenced -- it is a deleted function
745 // static yes_type test(U&, decltype(U(boost::declval<U&>()))* = 0);
747 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
748 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
749 #if defined(BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE)
750 template<class U> static typename add_reference<U>::type source();
751 static no_type test(...);
752 #ifdef BOOST_NO_CXX11_DECLTYPE
754 static yes_type test(U&, bool_<sizeof(U(source<U>()))>* = 0);
757 static yes_type test(U&, decltype(U(source<U>()))* = 0);
759 static const bool value = sizeof(test(source<T>())) == sizeof(yes_type);
761 static const bool value = !has_boost_move_no_copy_constructor_or_assign_type<T>::value;
766 //////////////////////////////////////
767 // is_copy_assignable
768 //////////////////////////////////////
769 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_NO_CXX11_DECLTYPE) \
770 && !defined(BOOST_INTEL_CXX_VERSION) && \
771 !(defined(BOOST_MSVC) && _MSC_VER == 1800)
772 #define BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE
776 struct is_copy_assignable
778 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
780 // error: function *function_name* cannot be referenced -- it is a deleted function
781 // static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
784 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
785 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
786 #if defined(BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE)
787 typedef char yes_type;
788 struct no_type { char dummy[2]; };
790 template <class U> static typename add_reference<U>::type source();
791 template <class U> static decltype(source<U&>() = source<const U&>(), yes_type() ) test(int);
792 template <class> static no_type test(...);
794 static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
796 static const bool value = !has_boost_move_no_copy_constructor_or_assign_type<T>::value;
800 //////////////////////////////////////
801 // is_trivially_destructible
802 //////////////////////////////////////
804 struct is_trivially_destructible
805 { static const bool value = BOOST_MOVE_IS_TRIVIALLY_DESTRUCTIBLE(T); };
807 //////////////////////////////////////
808 // is_trivially_default_constructible
809 //////////////////////////////////////
811 struct is_trivially_default_constructible
812 { static const bool value = BOOST_MOVE_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE(T); };
814 //////////////////////////////////////
815 // is_trivially_copy_constructible
816 //////////////////////////////////////
818 struct is_trivially_copy_constructible
820 //In several compilers BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE return true even with
821 //deleted copy constructors so make sure the type is copy constructible.
822 static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T);
825 //////////////////////////////////////
826 // is_trivially_move_constructible
827 //////////////////////////////////////
829 struct is_trivially_move_constructible
830 { static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE(T); };
832 //////////////////////////////////////
833 // is_trivially_copy_assignable
834 //////////////////////////////////////
836 struct is_trivially_copy_assignable
838 //In several compilers BOOST_MOVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE return true even with
839 //deleted copy constructors so make sure the type is copy constructible.
840 static const bool value = BOOST_MOVE_IS_TRIVIALLY_COPY_ASSIGNABLE(T);
843 //////////////////////////////////////
844 // is_trivially_move_assignable
845 //////////////////////////////////////
847 struct is_trivially_move_assignable
848 { static const bool value = BOOST_MOVE_IS_TRIVIALLY_MOVE_ASSIGNABLE(T); };
850 //////////////////////////////////////
851 // is_nothrow_default_constructible
852 //////////////////////////////////////
854 struct is_nothrow_default_constructible
856 { static const bool value = BOOST_MOVE_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE(T); };
858 //////////////////////////////////////
859 // is_nothrow_copy_constructible
860 //////////////////////////////////////
862 struct is_nothrow_copy_constructible
863 { static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_CONSTRUCTIBLE(T); };
865 //////////////////////////////////////
866 // is_nothrow_move_constructible
867 //////////////////////////////////////
869 struct is_nothrow_move_constructible
870 { static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T); };
872 //////////////////////////////////////
873 // is_nothrow_copy_assignable
874 //////////////////////////////////////
876 struct is_nothrow_copy_assignable
877 { static const bool value = BOOST_MOVE_IS_NOTHROW_COPY_ASSIGNABLE(T); };
879 //////////////////////////////////////
880 // is_nothrow_move_assignable
881 //////////////////////////////////////
883 struct is_nothrow_move_assignable
884 { static const bool value = BOOST_MOVE_IS_NOTHROW_MOVE_ASSIGNABLE(T); };
886 //////////////////////////////////////
887 // is_nothrow_swappable
888 //////////////////////////////////////
890 struct is_nothrow_swappable
892 static const bool value = is_empty<T>::value || is_pod<T>::value;
895 //////////////////////////////////////
897 //////////////////////////////////////
898 template <typename T>
899 struct alignment_of_hack
907 template <unsigned A, unsigned S>
908 struct alignment_logic
909 { static const std::size_t value = A < S ? A : S; };
911 template< typename T >
912 struct alignment_of_impl
913 #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
914 // With MSVC both the native __alignof operator
915 // and our own logic gets things wrong from time to time :-(
916 // Using a combination of the two seems to make the most of a bad job:
917 : alignment_logic< sizeof(alignment_of_hack<T>) - 2*sizeof(T), __alignof(T)>
919 #elif !defined(BOOST_MOVE_ALIGNMENT_OF)
920 : alignment_logic< sizeof(alignment_of_hack<T>) - 2*sizeof(T), sizeof(T)>
923 { static const std::size_t value = BOOST_MOVE_ALIGNMENT_OF(T); };
926 template< typename T >
928 : alignment_of_impl<T>
931 class alignment_dummy;
932 typedef void (*function_ptr)();
933 typedef int (alignment_dummy::*member_ptr);
934 typedef int (alignment_dummy::*member_function_ptr)();
935 struct alignment_struct
936 { long double dummy[4]; };
938 /////////////////////////////
940 /////////////////////////////
941 //This is not standard, but should work with all compilers
948 #ifdef BOOST_HAS_LONG_LONG
949 ::boost::long_long_type long_long_;
954 long double long_double_[4];
955 alignment_dummy *unknown_class_ptr_;
956 function_ptr function_ptr_;
957 member_function_ptr member_function_ptr_;
958 alignment_struct alignment_struct_;
961 typedef union max_align max_align_t;
963 /////////////////////////////
965 /////////////////////////////
967 #if !defined(BOOST_NO_ALIGNMENT)
969 template<std::size_t Len, std::size_t Align>
970 struct aligned_struct;
972 #define BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(A)\
973 template<std::size_t Len>\
974 struct BOOST_ALIGNMENT(A) aligned_struct<Len, A>\
976 unsigned char data[Len];\
980 //Up to 4K alignment (typical page size)
981 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1)
982 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x2)
983 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x4)
984 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x8)
985 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x10)
986 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x20)
987 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x40)
988 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x80)
989 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100)
990 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200)
991 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400)
992 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800)
993 BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)
995 #undef BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT
997 // Workaround for bogus [-Wignored-attributes] warning on GCC 6.x/7.x: don't use a type that "directly" carries the alignment attribute.
998 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82270
999 template<std::size_t Len, std::size_t Align>
1000 union aligned_struct_wrapper
1002 aligned_struct<Len, Align> aligner;
1003 unsigned char data[sizeof(aligned_struct<Len, Align>)];
1006 template<std::size_t Len, std::size_t Align>
1007 struct aligned_storage_impl
1009 typedef aligned_struct_wrapper<Len, Align> type;
1012 #else //BOOST_NO_ALIGNMENT
1014 template<class T, std::size_t Len>
1018 unsigned char data[Len];
1021 template<std::size_t Len, std::size_t Align, class T, bool Ok>
1022 struct aligned_next;
1024 template<std::size_t Len, std::size_t Align, class T>
1025 struct aligned_next<Len, Align, T, true>
1027 BOOST_STATIC_ASSERT((alignment_of<T>::value == Align));
1028 typedef aligned_union<T, Len> type;
1031 //End of search defaults to max_align_t
1032 template<std::size_t Len, std::size_t Align>
1033 struct aligned_next<Len, Align, max_align_t, false>
1034 { typedef aligned_union<max_align_t, Len> type; };
1036 //Now define a search list through types
1037 #define BOOST_MOVE_ALIGNED_NEXT_STEP(TYPE, NEXT_TYPE)\
1038 template<std::size_t Len, std::size_t Align>\
1039 struct aligned_next<Len, Align, TYPE, false>\
1040 : aligned_next<Len, Align, NEXT_TYPE, Align == alignment_of<NEXT_TYPE>::value>\
1043 BOOST_MOVE_ALIGNED_NEXT_STEP(long double, max_align_t)
1044 BOOST_MOVE_ALIGNED_NEXT_STEP(double, long double)
1045 #ifdef BOOST_HAS_LONG_LONG
1046 BOOST_MOVE_ALIGNED_NEXT_STEP(::boost::long_long_type, double)
1047 BOOST_MOVE_ALIGNED_NEXT_STEP(long, ::boost::long_long_type)
1049 BOOST_MOVE_ALIGNED_NEXT_STEP(long, double)
1051 BOOST_MOVE_ALIGNED_NEXT_STEP(int, long)
1052 BOOST_MOVE_ALIGNED_NEXT_STEP(short, int)
1053 BOOST_MOVE_ALIGNED_NEXT_STEP(char, short)
1054 #undef BOOST_MOVE_ALIGNED_NEXT_STEP
1056 template<std::size_t Len, std::size_t Align>
1057 struct aligned_storage_impl
1058 : aligned_next<Len, Align, char, Align == alignment_of<char>::value>
1063 template<std::size_t Len, std::size_t Align = alignment_of<max_align_t>::value>
1064 struct aligned_storage
1066 //Sanity checks for input parameters
1067 BOOST_STATIC_ASSERT(Align > 0);
1069 //Sanity checks for output type
1070 typedef typename aligned_storage_impl<Len ? Len : 1, Align>::type type;
1071 static const std::size_t value = alignment_of<type>::value;
1072 BOOST_STATIC_ASSERT(value >= Align);
1073 BOOST_STATIC_ASSERT((value % Align) == 0);
1075 //Just in case someone instantiates aligned_storage
1076 //instead of aligned_storage::type (typical error).
1081 } //namespace move_detail {
1082 } //namespace boost {
1084 #include <boost/move/detail/config_end.hpp>
1086 #endif //#ifndef BOOST_MOVE_DETAIL_TYPE_TRAITS_HPP