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 #ifndef EIGEN_META_H
00027 #define EIGEN_META_H
00028
00036 struct ei_meta_true { enum { ret = 1 }; };
00037 struct ei_meta_false { enum { ret = 0 }; };
00038
00039 template<bool Condition, typename Then, typename Else>
00040 struct ei_meta_if { typedef Then ret; };
00041
00042 template<typename Then, typename Else>
00043 struct ei_meta_if <false, Then, Else> { typedef Else ret; };
00044
00045 template<typename T, typename U> struct ei_is_same_type { enum { ret = 0 }; };
00046 template<typename T> struct ei_is_same_type<T,T> { enum { ret = 1 }; };
00047
00048 template<typename T> struct ei_unref { typedef T type; };
00049 template<typename T> struct ei_unref<T&> { typedef T type; };
00050
00051 template<typename T> struct ei_unpointer { typedef T type; };
00052 template<typename T> struct ei_unpointer<T*> { typedef T type; };
00053 template<typename T> struct ei_unpointer<T*const> { typedef T type; };
00054
00055 template<typename T> struct ei_unconst { typedef T type; };
00056 template<typename T> struct ei_unconst<const T> { typedef T type; };
00057 template<typename T> struct ei_unconst<T const &> { typedef T & type; };
00058 template<typename T> struct ei_unconst<T const *> { typedef T * type; };
00059
00060 template<typename T> struct ei_cleantype { typedef T type; };
00061 template<typename T> struct ei_cleantype<const T> { typedef typename ei_cleantype<T>::type type; };
00062 template<typename T> struct ei_cleantype<const T&> { typedef typename ei_cleantype<T>::type type; };
00063 template<typename T> struct ei_cleantype<T&> { typedef typename ei_cleantype<T>::type type; };
00064 template<typename T> struct ei_cleantype<const T*> { typedef typename ei_cleantype<T>::type type; };
00065 template<typename T> struct ei_cleantype<T*> { typedef typename ei_cleantype<T>::type type; };
00066
00074 template<typename T> struct ei_result_of {};
00075
00076 struct ei_has_none {int a[1];};
00077 struct ei_has_std_result_type {int a[2];};
00078 struct ei_has_tr1_result {int a[3];};
00079
00080 template<typename Func, typename ArgType, int SizeOf=sizeof(ei_has_none)>
00081 struct ei_unary_result_of_select {typedef ArgType type;};
00082
00083 template<typename Func, typename ArgType>
00084 struct ei_unary_result_of_select<Func, ArgType, sizeof(ei_has_std_result_type)> {typedef typename Func::result_type type;};
00085
00086 template<typename Func, typename ArgType>
00087 struct ei_unary_result_of_select<Func, ArgType, sizeof(ei_has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
00088
00089 template<typename Func, typename ArgType>
00090 struct ei_result_of<Func(ArgType)> {
00091 template<typename T>
00092 static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
00093 template<typename T>
00094 static ei_has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
00095 static ei_has_none testFunctor(...);
00096
00097
00098 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
00099 typedef typename ei_unary_result_of_select<Func, ArgType, FunctorType>::type type;
00100 };
00101
00102 template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(ei_has_none)>
00103 struct ei_binary_result_of_select {typedef ArgType0 type;};
00104
00105 template<typename Func, typename ArgType0, typename ArgType1>
00106 struct ei_binary_result_of_select<Func, ArgType0, ArgType1, sizeof(ei_has_std_result_type)>
00107 {typedef typename Func::result_type type;};
00108
00109 template<typename Func, typename ArgType0, typename ArgType1>
00110 struct ei_binary_result_of_select<Func, ArgType0, ArgType1, sizeof(ei_has_tr1_result)>
00111 {typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
00112
00113 template<typename Func, typename ArgType0, typename ArgType1>
00114 struct ei_result_of<Func(ArgType0,ArgType1)> {
00115 template<typename T>
00116 static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
00117 template<typename T>
00118 static ei_has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
00119 static ei_has_none testFunctor(...);
00120
00121
00122 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
00123 typedef typename ei_binary_result_of_select<Func, ArgType0, ArgType1, FunctorType>::type type;
00124 };
00125
00129 template<int Y,
00130 int InfX = 0,
00131 int SupX = ((Y==1) ? 1 : Y/2),
00132 bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) >
00133
00134 class ei_meta_sqrt
00135 {
00136 enum {
00137 MidX = (InfX+SupX)/2,
00138 TakeInf = MidX*MidX > Y ? 1 : 0,
00139 NewInf = int(TakeInf) ? InfX : int(MidX),
00140 NewSup = int(TakeInf) ? int(MidX) : SupX
00141 };
00142 public:
00143 enum { ret = ei_meta_sqrt<Y,NewInf,NewSup>::ret };
00144 };
00145
00146 template<int Y, int InfX, int SupX>
00147 class ei_meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
00148
00150 template<typename T, typename U> struct ei_scalar_product_traits
00151 {
00152
00153
00154 typedef T ReturnType;
00155 };
00156
00157 template<typename T> struct ei_scalar_product_traits<T,T>
00158 {
00159
00160 typedef T ReturnType;
00161 };
00162
00163 template<typename T> struct ei_scalar_product_traits<T,std::complex<T> >
00164 {
00165
00166 typedef std::complex<T> ReturnType;
00167 };
00168
00169 template<typename T> struct ei_scalar_product_traits<std::complex<T>, T>
00170 {
00171
00172 typedef std::complex<T> ReturnType;
00173 };
00174
00175
00176 template<typename Scalar, typename ArgType0, typename ArgType1>
00177 struct ei_result_of<ei_scalar_product_op<Scalar>(ArgType0,ArgType1)> {
00178 typedef typename ei_scalar_product_traits<typename ei_cleantype<ArgType0>::type, typename ei_cleantype<ArgType1>::type>::ReturnType type;
00179 };
00180
00181
00182
00183 #endif // EIGEN_META_H