|
Sierra Toolkit
Version of the Day
|
00001 #ifndef RDESTL_TYPETRAITS_H 00002 #define RDESTL_TYPETRAITS_H 00003 00004 namespace rde 00005 { 00006 00007 template<typename T> struct is_integral 00008 { 00009 enum { value = false }; 00010 }; 00011 00012 template<typename T> struct is_floating_point 00013 { 00014 enum { value = false }; 00015 }; 00016 00017 #define RDE_INTEGRAL(TYPE) template<> struct is_integral<TYPE> { enum { value = true }; } 00018 00019 RDE_INTEGRAL(char); 00020 RDE_INTEGRAL(bool); 00021 RDE_INTEGRAL(short); 00022 RDE_INTEGRAL(int); 00023 RDE_INTEGRAL(long); 00024 RDE_INTEGRAL(wchar_t); 00025 00026 template<> struct is_floating_point<float> { enum { value = true }; }; 00027 template<> struct is_floating_point<double> { enum { value = true }; }; 00028 00029 template<typename T> struct is_pointer 00030 { 00031 enum { value = false }; 00032 }; 00033 template<typename T> struct is_pointer<T*> 00034 { 00035 enum { value = true }; 00036 }; 00037 00038 template<typename T> struct is_pod 00039 { 00040 enum { value = false }; 00041 }; 00042 00043 template<typename T> struct is_fundamental 00044 { 00045 enum 00046 { 00047 value = is_integral<T>::value || is_floating_point<T>::value 00048 }; 00049 }; 00050 00051 template<typename T> struct has_trivial_constructor 00052 { 00053 enum 00054 { 00055 value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value 00056 }; 00057 }; 00058 00059 template<typename T> struct has_trivial_copy 00060 { 00061 enum 00062 { 00063 value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value 00064 }; 00065 }; 00066 00067 template<typename T> struct has_trivial_assign 00068 { 00069 enum 00070 { 00071 value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value 00072 }; 00073 }; 00074 00075 template<typename T> struct has_trivial_destructor 00076 { 00077 enum 00078 { 00079 value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value 00080 }; 00081 }; 00082 00083 template<typename T> struct has_cheap_compare 00084 { 00085 enum 00086 { 00087 value = has_trivial_copy<T>::value && sizeof(T) <= 4 00088 }; 00089 }; 00090 00091 } // namespace rde 00092 00093 //----------------------------------------------------------------------------- 00094 #endif // #ifndef RDESTL_TYPETRAITS_H 00095 00096