54 #ifndef BASE_TYPE_TRAITS_H_ 55 #define BASE_TYPE_TRAITS_H_ 57 #include <stk_util/util/sparseconfig.h> 60 _START_GOOGLE_NAMESPACE_
67 template<
class T, T v>
68 struct integral_constant {
69 static const T value = v;
71 typedef integral_constant<T, v> type;
74 template <
class T, T v>
const T integral_constant<T, v>::value;
78 typedef integral_constant<bool, true> true_type;
79 typedef integral_constant<bool, false> false_type;
89 template <
class T>
struct is_integral;
90 template <
class T>
struct is_floating_point;
91 template <
class T>
struct is_pointer;
93 #if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) 95 template <
class T>
struct is_enum;
97 template <
class T>
struct is_reference;
98 template <
class T>
struct is_pod;
99 template <
class T>
struct has_trivial_constructor;
100 template <
class T>
struct has_trivial_copy;
101 template <
class T>
struct has_trivial_assign;
102 template <
class T>
struct has_trivial_destructor;
103 template <
class T>
struct remove_const;
104 template <
class T>
struct remove_volatile;
105 template <
class T>
struct remove_cv;
106 template <
class T>
struct remove_reference;
107 template <
class T>
struct add_reference;
108 template <
class T>
struct remove_pointer;
109 template <
class T,
class U>
struct is_same;
110 #if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) 111 template <
class From,
class To>
struct is_convertible;
115 template <
class T>
struct is_integral : false_type { };
116 template<>
struct is_integral<bool> : true_type { };
117 template<>
struct is_integral<char> : true_type { };
118 template<>
struct is_integral<unsigned char> : true_type { };
119 template<>
struct is_integral<signed char> : true_type { };
120 #if defined(_MSC_VER) 124 template<>
struct is_integral<__wchar_t> : true_type { };
126 template<>
struct is_integral<wchar_t> : true_type { };
128 template<>
struct is_integral<short> : true_type { };
129 template<>
struct is_integral<unsigned short> : true_type { };
130 template<>
struct is_integral<int> : true_type { };
131 template<>
struct is_integral<unsigned int> : true_type { };
132 template<>
struct is_integral<long> : true_type { };
133 template<>
struct is_integral<unsigned long> : true_type { };
134 #ifdef HAVE_LONG_LONG 135 template<>
struct is_integral<long long> : true_type { };
136 template<>
struct is_integral<unsigned long long> : true_type { };
141 template <
class T>
struct is_floating_point : false_type { };
142 template<>
struct is_floating_point<float> : true_type { };
143 template<>
struct is_floating_point<double> : true_type { };
144 template<>
struct is_floating_point<long double> : true_type { };
148 template <
class T>
struct is_pointer : false_type { };
149 template <
class T>
struct is_pointer<T*> : true_type { };
151 #if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) 155 template <
class T>
struct is_class_or_union {
156 template <
class U>
static small_ tester(
void (U::*)());
157 template <
class U>
static big_ tester(...);
158 static const bool value =
sizeof(tester<T>(0)) ==
sizeof(small_);
163 template <
bool NotUnum,
class T>
struct is_enum_impl
164 : is_convertible<typename add_reference<T>::type, int> { };
166 template <
class T>
struct is_enum_impl<true, T> : false_type { };
184 template <
class T>
struct is_enum
185 : internal::is_enum_impl<
186 is_same<T, void>::value ||
187 is_integral<T>::value ||
188 is_floating_point<T>::value ||
189 is_reference<T>::value ||
190 internal::is_class_or_union<T>::value,
193 template <
class T>
struct is_enum<const T> : is_enum<T> { };
194 template <
class T>
struct is_enum<volatile T> : is_enum<T> { };
195 template <
class T>
struct is_enum<const volatile T> : is_enum<T> { };
200 template<
typename T>
struct is_reference : false_type {};
201 template<
typename T>
struct is_reference<T&> : true_type {};
207 template <
class T>
struct is_pod
208 : integral_constant<bool, (is_integral<T>::value ||
209 is_floating_point<T>::value ||
210 #if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
214 is_pointer<T>::value)> { };
215 template <class T> struct is_pod<const T> : is_pod<T> { };
223 template <class T> struct has_trivial_constructor : is_pod<T> { };
224 template <class T, class U> struct has_trivial_constructor<std::pair<T, U> >
225 : integral_constant<bool,
226 (has_trivial_constructor<T>::value &&
227 has_trivial_constructor<U>::value)> { };
228 template <class A, int N> struct has_trivial_constructor<A[N]>
229 : has_trivial_constructor<A> { };
230 template <class T> struct has_trivial_constructor<const T>
231 : has_trivial_constructor<T> { };
238 template <class T> struct has_trivial_copy : is_pod<T> { };
239 template <class T, class U> struct has_trivial_copy<std::pair<T, U> >
240 : integral_constant<bool,
241 (has_trivial_copy<T>::value &&
242 has_trivial_copy<U>::value)> { };
243 template <class A, int N> struct has_trivial_copy<A[N]>
244 : has_trivial_copy<A> { };
245 template <class T> struct has_trivial_copy<const T> : has_trivial_copy<T> { };
251 template <class T> struct has_trivial_assign : is_pod<T> { };
252 template <class T, class U> struct has_trivial_assign<std::pair<T, U> >
253 : integral_constant<bool,
254 (has_trivial_assign<T>::value &&
255 has_trivial_assign<U>::value)> { };
256 template <class A, int N> struct has_trivial_assign<A[N]>
257 : has_trivial_assign<A> { };
264 template <class T> struct has_trivial_destructor : is_pod<T> { };
265 template <class T, class U> struct has_trivial_destructor<std::pair<T, U> >
266 : integral_constant<bool,
267 (has_trivial_destructor<T>::value &&
268 has_trivial_destructor<U>::value)> { };
269 template <class A, int N> struct has_trivial_destructor<A[N]>
270 : has_trivial_destructor<A> { };
271 template <class T> struct has_trivial_destructor<const T>
272 : has_trivial_destructor<T> { };
275 template<typename T> struct remove_const { typedef T type; };
276 template<typename T> struct remove_const<T const> { typedef T type; };
277 template<typename T> struct remove_volatile { typedef T type; };
278 template<typename T> struct remove_volatile<T volatile> { typedef T type; };
279 template<typename T> struct remove_cv {
280 typedef typename remove_const<typename remove_volatile<T>::type>::type type;
285 template<typename T> struct remove_reference { typedef T type; };
286 template<typename T> struct remove_reference<T&> { typedef T type; };
288 template <typename T> struct add_reference { typedef T& type; };
289 template <typename T> struct add_reference<T&> { typedef T& type; };
292 template<typename T> struct remove_pointer { typedef T type; };
293 template<typename T> struct remove_pointer<T*> { typedef T type; };
294 template<typename T> struct remove_pointer<T* const> { typedef T type; };
295 template<typename T> struct remove_pointer<T* volatile> { typedef T type; };
296 template<typename T> struct remove_pointer<T* const volatile> {
300 template<typename T, typename U> struct is_same : public false_type { };
301 template<typename T> struct is_same<T, T> : public true_type { };
304 #if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
316 template <typename From, typename To>
317 struct ConvertHelper {
318 static small_ Test(To);
319 static big_ Test(...);
320 static From Create();
325 template <typename From, typename To>
326 struct is_convertible
327 : integral_constant<bool,
328 sizeof(internal::ConvertHelper<From, To>::Test(
329 internal::ConvertHelper<From, To>::Create()))
334 _END_GOOGLE_NAMESPACE_