2 // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_INTRINSICS_HPP_INCLUDED
10 #define BOOST_TT_INTRINSICS_HPP_INCLUDED
12 #ifndef BOOST_TT_CONFIG_HPP_INCLUDED
13 #include <boost/type_traits/config.hpp>
17 // Helper macros for builtin compiler support.
18 // If your compiler has builtin support for any of the following
19 // traits concepts, then redefine the appropriate macros to pick
20 // up on the compiler support:
22 // (these should largely ignore cv-qualifiers)
23 // BOOST_IS_UNION(T) should evaluate to true if T is a union type
24 // BOOST_IS_POD(T) should evaluate to true if T is a POD type
25 // BOOST_IS_EMPTY(T) should evaluate to true if T is an empty struct or union
26 // BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) should evaluate to true if "T x;" has no effect
27 // BOOST_HAS_TRIVIAL_COPY(T) should evaluate to true if T(t) <==> memcpy
28 // BOOST_HAS_TRIVIAL_ASSIGN(T) should evaluate to true if t = u <==> memcpy
29 // BOOST_HAS_TRIVIAL_DESTRUCTOR(T) should evaluate to true if ~T() has no effect
30 // BOOST_HAS_NOTHROW_CONSTRUCTOR(T) should evaluate to true if "T x;" can not throw
31 // BOOST_HAS_NOTHROW_COPY(T) should evaluate to true if T(t) can not throw
32 // BOOST_HAS_NOTHROW_ASSIGN(T) should evaluate to true if t = u can not throw
33 // BOOST_HAS_VIRTUAL_DESTRUCTOR(T) should evaluate to true T has a virtual destructor
35 // The following can also be defined: when detected our implementation is greatly simplified.
37 // BOOST_IS_ABSTRACT(T) true if T is an abstract type
38 // BOOST_IS_BASE_OF(T,U) true if T is a base class of U
39 // BOOST_IS_CLASS(T) true if T is a class type
40 // BOOST_IS_CONVERTIBLE(T,U) true if T is convertible to U
41 // BOOST_IS_ENUM(T) true is T is an enum
42 // BOOST_IS_POLYMORPHIC(T) true if T is a polymorphic type
43 // BOOST_ALIGNMENT_OF(T) should evaluate to the alignment requirements of type T.
45 #ifdef BOOST_HAS_SGI_TYPE_TRAITS
46 // Hook into SGI's __type_traits class, this will pick up user supplied
47 // specializations as well as SGI - compiler supplied specializations.
48 # include <boost/type_traits/is_same.hpp>
50 // There are two different versions of type_traits.h on NetBSD on Spark
51 // use an implicit include via algorithm instead, to make sure we get
52 // the same version as the std lib:
55 # include <type_traits.h>
57 # define BOOST_IS_POD(T) ::boost::is_same< typename ::__type_traits<T>::is_POD_type, ::__true_type>::value
58 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) ::boost::is_same< typename ::__type_traits<T>::has_trivial_default_constructor, ::__true_type>::value
59 # define BOOST_HAS_TRIVIAL_COPY(T) ::boost::is_same< typename ::__type_traits<T>::has_trivial_copy_constructor, ::__true_type>::value
60 # define BOOST_HAS_TRIVIAL_ASSIGN(T) ::boost::is_same< typename ::__type_traits<T>::has_trivial_assignment_operator, ::__true_type>::value
61 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) ::boost::is_same< typename ::__type_traits<T>::has_trivial_destructor, ::__true_type>::value
64 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
68 #if defined(__MSL_CPP__) && (__MSL_CPP__ >= 0x8000)
69 // Metrowerks compiler is acquiring intrinsic type traits support
70 // post version 8. We hook into the published interface to pick up
71 // user defined specializations as well as compiler intrinsics as
72 // and when they become available:
73 # include <msl_utility>
74 # define BOOST_IS_UNION(T) BOOST_STD_EXTENSION_NAMESPACE::is_union<T>::value
75 # define BOOST_IS_POD(T) BOOST_STD_EXTENSION_NAMESPACE::is_POD<T>::value
76 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_default_ctor<T>::value
77 # define BOOST_HAS_TRIVIAL_COPY(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_copy_ctor<T>::value
78 # define BOOST_HAS_TRIVIAL_ASSIGN(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_assignment<T>::value
79 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) BOOST_STD_EXTENSION_NAMESPACE::has_trivial_dtor<T>::value
80 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
83 #if defined(BOOST_MSVC) && defined(BOOST_MSVC_FULL_VER) && (BOOST_MSVC_FULL_VER >=140050215)
84 # include <boost/type_traits/is_same.hpp>
86 # define BOOST_IS_UNION(T) __is_union(T)
87 # define BOOST_IS_POD(T) (__is_pod(T) && __has_trivial_constructor(T))
88 # define BOOST_IS_EMPTY(T) __is_empty(T)
89 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T)
90 # define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T)|| ( ::boost::is_pod<T>::value && !::boost::is_volatile<T>::value))
91 # define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) || ( ::boost::is_pod<T>::value && ! ::boost::is_const<T>::value && !::boost::is_volatile<T>::value))
92 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) || ::boost::is_pod<T>::value)
93 # define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) || ::boost::has_trivial_constructor<T>::value)
94 # define BOOST_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T) || ::boost::has_trivial_copy<T>::value)
95 # define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) || ::boost::has_trivial_assign<T>::value)
96 # define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
98 # define BOOST_IS_ABSTRACT(T) __is_abstract(T)
99 # define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_same<T,U>::value)
100 # define BOOST_IS_CLASS(T) __is_class(T)
101 # define BOOST_IS_CONVERTIBLE(T,U) ((__is_convertible_to(T,U) || is_same<T,U>::value) && !__is_abstract(U))
102 # define BOOST_IS_ENUM(T) __is_enum(T)
103 // This one doesn't quite always do the right thing:
104 // # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T)
105 // This one fails if the default alignment has been changed with /Zp:
106 // # define BOOST_ALIGNMENT_OF(T) __alignof(T)
108 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
111 #if defined(__DMC__) && (__DMC__ >= 0x848)
112 // For Digital Mars C++, www.digitalmars.com
113 # define BOOST_IS_UNION(T) (__typeinfo(T) & 0x400)
114 # define BOOST_IS_POD(T) (__typeinfo(T) & 0x800)
115 # define BOOST_IS_EMPTY(T) (__typeinfo(T) & 0x1000)
116 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) (__typeinfo(T) & 0x10)
117 # define BOOST_HAS_TRIVIAL_COPY(T) (__typeinfo(T) & 0x20)
118 # define BOOST_HAS_TRIVIAL_ASSIGN(T) (__typeinfo(T) & 0x40)
119 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__typeinfo(T) & 0x8)
120 # define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__typeinfo(T) & 0x80)
121 # define BOOST_HAS_NOTHROW_COPY(T) (__typeinfo(T) & 0x100)
122 # define BOOST_HAS_NOTHROW_ASSIGN(T) (__typeinfo(T) & 0x200)
123 # define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) (__typeinfo(T) & 0x4)
124 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
127 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) && !defined(__GCCXML__)))
128 # include <boost/type_traits/is_same.hpp>
129 # include <boost/type_traits/is_reference.hpp>
130 # include <boost/type_traits/is_volatile.hpp>
133 # define BOOST_INTEL_TT_OPTS || is_pod<T>::value
135 # define BOOST_INTEL_TT_OPTS
138 # define BOOST_IS_UNION(T) __is_union(T)
139 # define BOOST_IS_POD(T) __is_pod(T)
140 # define BOOST_IS_EMPTY(T) __is_empty(T)
141 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) ((__has_trivial_constructor(T) BOOST_INTEL_TT_OPTS) && ! ::boost::is_volatile<T>::value)
142 # define BOOST_HAS_TRIVIAL_COPY(T) ((__has_trivial_copy(T) BOOST_INTEL_TT_OPTS) && !is_reference<T>::value && ! ::boost::is_volatile<T>::value)
143 # define BOOST_HAS_TRIVIAL_ASSIGN(T) ((__has_trivial_assign(T) BOOST_INTEL_TT_OPTS) && ! ::boost::is_volatile<T>::value && ! ::boost::is_const<T>::value)
144 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) BOOST_INTEL_TT_OPTS)
145 # define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) BOOST_INTEL_TT_OPTS)
146 # define BOOST_HAS_NOTHROW_COPY(T) ((__has_nothrow_copy(T) BOOST_INTEL_TT_OPTS) && !is_volatile<T>::value && !is_reference<T>::value)
147 # define BOOST_HAS_NOTHROW_ASSIGN(T) ((__has_nothrow_assign(T) BOOST_INTEL_TT_OPTS) && !is_volatile<T>::value && !is_const<T>::value)
148 # define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
150 # define BOOST_IS_ABSTRACT(T) __is_abstract(T)
151 # define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_same<T,U>::value)
152 # define BOOST_IS_CLASS(T) __is_class(T)
153 # define BOOST_IS_ENUM(T) __is_enum(T)
154 # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T)
155 # if (!defined(unix) && !defined(__unix__)) || defined(__LP64__)
156 // GCC sometimes lies about alignment requirements
157 // of type double on 32-bit unix platforms, use the
158 // old implementation instead in that case:
159 # define BOOST_ALIGNMENT_OF(T) __alignof__(T)
162 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
165 #if defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
166 # include <boost/type_traits/is_same.hpp>
167 # include <boost/type_traits/is_reference.hpp>
168 # include <boost/type_traits/is_volatile.hpp>
170 # define BOOST_IS_UNION(T) __is_union(T)
171 # define BOOST_IS_POD(T) __is_pod(T)
172 # define BOOST_IS_EMPTY(T) __is_empty(T)
173 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T)
174 # define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && !is_reference<T>::value && && !is_volatile<T>::value)
175 # define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) && !is_volatile<T>::value)
176 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
177 # define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) __has_nothrow_constructor(T)
178 # define BOOST_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T) && !is_volatile<T>::value && !is_reference<T>::value)
179 # define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile<T>::value)
180 # define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
182 # define BOOST_IS_ABSTRACT(T) __is_abstract(T)
183 # define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_same<T,U>::value)
184 # define BOOST_IS_CLASS(T) __is_class(T)
185 # define BOOST_IS_ENUM(T) __is_enum(T)
186 # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T)
187 # define BOOST_ALIGNMENT_OF(T) __alignof__(T)
189 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
192 # if defined(__CODEGEARC__)
193 # include <boost/type_traits/is_same.hpp>
194 # include <boost/type_traits/is_reference.hpp>
195 # include <boost/type_traits/is_volatile.hpp>
196 # include <boost/type_traits/is_void.hpp>
198 # define BOOST_IS_UNION(T) __is_union(T)
199 # define BOOST_IS_POD(T) __is_pod(T)
200 # define BOOST_IS_EMPTY(T) __is_empty(T)
201 # define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) (__has_trivial_default_constructor(T))
202 # define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy_constructor(T) && !is_volatile<T>::value && !is_reference<T>::value)
203 # define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) && !is_volatile<T>::value)
204 # define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T))
205 # define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_default_constructor(T))
206 # define BOOST_HAS_NOTHROW_COPY(T) (__has_nothrow_copy_constructor(T) && !is_volatile<T>::value && !is_reference<T>::value)
207 # define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile<T>::value)
208 # define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
210 # define BOOST_IS_ABSTRACT(T) __is_abstract(T)
211 # define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_void<T>::value && !is_void<U>::value)
212 # define BOOST_IS_CLASS(T) __is_class(T)
213 # define BOOST_IS_CONVERTIBLE(T,U) (__is_convertible(T,U) || is_void<U>::value)
214 # define BOOST_IS_ENUM(T) __is_enum(T)
215 # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T)
216 # define BOOST_ALIGNMENT_OF(T) alignof(T)
218 # define BOOST_HAS_TYPE_TRAITS_INTRINSICS
221 #endif // BOOST_TT_INTRINSICS_HPP_INCLUDED