type_utils.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef PB_DS_TYPE_UTILS_HPP
00043 #define PB_DS_TYPE_UTILS_HPP
00044
00045 #include <cstddef>
00046 #include <utility>
00047 #include <tr1/type_traits>
00048 #include <ext/type_traits.h>
00049 #include <ext/numeric_traits.h>
00050
00051 namespace __gnu_pbds
00052 {
00053 namespace detail
00054 {
00055 using std::tr1::is_same;
00056 using std::tr1::is_const;
00057 using std::tr1::is_pointer;
00058 using std::tr1::is_reference;
00059 using std::tr1::is_fundamental;
00060 using std::tr1::is_member_object_pointer;
00061 using std::tr1::is_member_pointer;
00062 using std::tr1::is_base_of;
00063 using std::tr1::remove_const;
00064 using std::tr1::remove_reference;
00065
00066
00067
00068
00069 using std::tr1::integral_constant;
00070 typedef std::tr1::integral_constant<int, 1> true_type;
00071 typedef std::tr1::integral_constant<int, 0> false_type;
00072
00073 using __gnu_cxx::__conditional_type;
00074 using __gnu_cxx::__numeric_traits;
00075
00076 template<typename T>
00077 struct is_const_pointer
00078 {
00079 enum
00080 {
00081 value = is_const<T>::value && is_pointer<T>::value
00082 };
00083 };
00084
00085 template<typename T>
00086 struct is_const_reference
00087 {
00088 enum
00089 {
00090 value = is_const<T>::value && is_reference<T>::value
00091 };
00092 };
00093
00094 template<typename T>
00095 struct is_simple
00096 {
00097 enum
00098 {
00099 value = is_fundamental<typename remove_const<T>::type>::value
00100 || is_pointer<typename remove_const<T>::type>::value
00101 || is_member_pointer<T>::value
00102 };
00103 };
00104
00105 template<typename T>
00106 class is_pair
00107 {
00108 private:
00109 template<typename U>
00110 struct is_pair_imp
00111 {
00112 enum
00113 {
00114 value = 0
00115 };
00116 };
00117
00118 template<typename U, typename V>
00119 struct is_pair_imp<std::pair<U,V> >
00120 {
00121 enum
00122 {
00123 value = 1
00124 };
00125 };
00126
00127 public:
00128 enum
00129 {
00130 value = is_pair_imp<T>::value
00131 };
00132 };
00133
00134
00135 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00136 #define PB_DS_STATIC_ASSERT(UNIQUE, E) static_assert(E, #UNIQUE)
00137 #else
00138 template<bool>
00139 struct __static_assert;
00140
00141 template<>
00142 struct __static_assert<true>
00143 { };
00144
00145 template<int>
00146 struct __static_assert_dumclass
00147 {
00148 enum
00149 {
00150 v = 1
00151 };
00152 };
00153
00154 #define PB_DS_STATIC_ASSERT(UNIQUE, E) \
00155 typedef __gnu_pbds::detail::__static_assert_dumclass<sizeof(__gnu_pbds::detail::__static_assert<bool(E)>)> UNIQUE##__static_assert_type
00156
00157 #endif
00158
00159 template<typename Type>
00160 struct type_to_type
00161 {
00162 typedef Type type;
00163 };
00164 }
00165 }
00166
00167 #endif