Sierra Toolkit  Version of the Day
type_traits_rdestl.h
1 #ifndef RDESTL_TYPETRAITS_H
2 #define RDESTL_TYPETRAITS_H
3 
4 namespace rde
5 {
6 
7 template<typename T> struct is_integral
8 {
9  enum { value = false };
10 };
11 
12 template<typename T> struct is_floating_point
13 {
14  enum { value = false };
15 };
16 
17 #define RDE_INTEGRAL(TYPE) template<> struct is_integral<TYPE> { enum { value = true }; }
18 
19 RDE_INTEGRAL(char);
20 RDE_INTEGRAL(bool);
21 RDE_INTEGRAL(short);
22 RDE_INTEGRAL(int);
23 RDE_INTEGRAL(long);
24 RDE_INTEGRAL(wchar_t);
25 
26 template<> struct is_floating_point<float> { enum { value = true }; };
27 template<> struct is_floating_point<double> { enum { value = true }; };
28 
29 template<typename T> struct is_pointer
30 {
31  enum { value = false };
32 };
33 template<typename T> struct is_pointer<T*>
34 {
35  enum { value = true };
36 };
37 
38 template<typename T> struct is_pod
39 {
40  enum { value = false };
41 };
42 
43 template<typename T> struct is_fundamental
44 {
45  enum
46  {
47  value = is_integral<T>::value || is_floating_point<T>::value
48  };
49 };
50 
51 template<typename T> struct has_trivial_constructor
52 {
53  enum
54  {
55  value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
56  };
57 };
58 
59 template<typename T> struct has_trivial_copy
60 {
61  enum
62  {
63  value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
64  };
65 };
66 
67 template<typename T> struct has_trivial_assign
68 {
69  enum
70  {
71  value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
72  };
73 };
74 
75 template<typename T> struct has_trivial_destructor
76 {
77  enum
78  {
79  value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
80  };
81 };
82 
83 template<typename T> struct has_cheap_compare
84 {
85  enum
86  {
87  value = has_trivial_copy<T>::value && sizeof(T) <= 4
88  };
89 };
90 
91 } // namespace rde
92 
93 //-----------------------------------------------------------------------------
94 #endif // #ifndef RDESTL_TYPETRAITS_H
95 
96