00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EIGEN_META_H
00012 #define EIGEN_META_H
00013
00014 namespace Eigen {
00015
00016 namespace internal {
00017
00025 struct true_type { enum { value = 1 }; };
00026 struct false_type { enum { value = 0 }; };
00027
00028 template<bool Condition, typename Then, typename Else>
00029 struct conditional { typedef Then type; };
00030
00031 template<typename Then, typename Else>
00032 struct conditional <false, Then, Else> { typedef Else type; };
00033
00034 template<typename T, typename U> struct is_same { enum { value = 0 }; };
00035 template<typename T> struct is_same<T,T> { enum { value = 1 }; };
00036
00037 template<typename T> struct remove_reference { typedef T type; };
00038 template<typename T> struct remove_reference<T&> { typedef T type; };
00039
00040 template<typename T> struct remove_pointer { typedef T type; };
00041 template<typename T> struct remove_pointer<T*> { typedef T type; };
00042 template<typename T> struct remove_pointer<T*const> { typedef T type; };
00043
00044 template <class T> struct remove_const { typedef T type; };
00045 template <class T> struct remove_const<const T> { typedef T type; };
00046 template <class T> struct remove_const<const T[]> { typedef T type[]; };
00047 template <class T, unsigned int Size> struct remove_const<const T[Size]> { typedef T type[Size]; };
00048
00049 template<typename T> struct remove_all { typedef T type; };
00050 template<typename T> struct remove_all<const T> { typedef typename remove_all<T>::type type; };
00051 template<typename T> struct remove_all<T const&> { typedef typename remove_all<T>::type type; };
00052 template<typename T> struct remove_all<T&> { typedef typename remove_all<T>::type type; };
00053 template<typename T> struct remove_all<T const*> { typedef typename remove_all<T>::type type; };
00054 template<typename T> struct remove_all<T*> { typedef typename remove_all<T>::type type; };
00055
00056 template<typename T> struct is_arithmetic { enum { value = false }; };
00057 template<> struct is_arithmetic<float> { enum { value = true }; };
00058 template<> struct is_arithmetic<double> { enum { value = true }; };
00059 template<> struct is_arithmetic<long double> { enum { value = true }; };
00060 template<> struct is_arithmetic<bool> { enum { value = true }; };
00061 template<> struct is_arithmetic<char> { enum { value = true }; };
00062 template<> struct is_arithmetic<signed char> { enum { value = true }; };
00063 template<> struct is_arithmetic<unsigned char> { enum { value = true }; };
00064 template<> struct is_arithmetic<signed short> { enum { value = true }; };
00065 template<> struct is_arithmetic<unsigned short>{ enum { value = true }; };
00066 template<> struct is_arithmetic<signed int> { enum { value = true }; };
00067 template<> struct is_arithmetic<unsigned int> { enum { value = true }; };
00068 template<> struct is_arithmetic<signed long> { enum { value = true }; };
00069 template<> struct is_arithmetic<unsigned long> { enum { value = true }; };
00070
00071 template <typename T> struct add_const { typedef const T type; };
00072 template <typename T> struct add_const<T&> { typedef T& type; };
00073
00074 template <typename T> struct is_const { enum { value = 0 }; };
00075 template <typename T> struct is_const<T const> { enum { value = 1 }; };
00076
00077 template<typename T> struct add_const_on_value_type { typedef const T type; };
00078 template<typename T> struct add_const_on_value_type<T&> { typedef T const& type; };
00079 template<typename T> struct add_const_on_value_type<T*> { typedef T const* type; };
00080 template<typename T> struct add_const_on_value_type<T* const> { typedef T const* const type; };
00081 template<typename T> struct add_const_on_value_type<T const* const> { typedef T const* const type; };
00082
00086 template<bool Condition, typename T> struct enable_if;
00087
00088 template<typename T> struct enable_if<true,T>
00089 { typedef T type; };
00090
00091
00092
00096 class noncopyable
00097 {
00098 noncopyable(const noncopyable&);
00099 const noncopyable& operator=(const noncopyable&);
00100 protected:
00101 noncopyable() {}
00102 ~noncopyable() {}
00103 };
00104
00105
00113 template<typename T> struct result_of {};
00114
00115 struct has_none {int a[1];};
00116 struct has_std_result_type {int a[2];};
00117 struct has_tr1_result {int a[3];};
00118
00119 template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
00120 struct unary_result_of_select {typedef ArgType type;};
00121
00122 template<typename Func, typename ArgType>
00123 struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
00124
00125 template<typename Func, typename ArgType>
00126 struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
00127
00128 template<typename Func, typename ArgType>
00129 struct result_of<Func(ArgType)> {
00130 template<typename T>
00131 static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
00132 template<typename T>
00133 static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
00134 static has_none testFunctor(...);
00135
00136
00137 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
00138 typedef typename unary_result_of_select<Func, ArgType, FunctorType>::type type;
00139 };
00140
00141 template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(has_none)>
00142 struct binary_result_of_select {typedef ArgType0 type;};
00143
00144 template<typename Func, typename ArgType0, typename ArgType1>
00145 struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_std_result_type)>
00146 {typedef typename Func::result_type type;};
00147
00148 template<typename Func, typename ArgType0, typename ArgType1>
00149 struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)>
00150 {typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
00151
00152 template<typename Func, typename ArgType0, typename ArgType1>
00153 struct result_of<Func(ArgType0,ArgType1)> {
00154 template<typename T>
00155 static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
00156 template<typename T>
00157 static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
00158 static has_none testFunctor(...);
00159
00160
00161 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
00162 typedef typename binary_result_of_select<Func, ArgType0, ArgType1, FunctorType>::type type;
00163 };
00164
00168 template<int Y,
00169 int InfX = 0,
00170 int SupX = ((Y==1) ? 1 : Y/2),
00171 bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) >
00172
00173 class meta_sqrt
00174 {
00175 enum {
00176 MidX = (InfX+SupX)/2,
00177 TakeInf = MidX*MidX > Y ? 1 : 0,
00178 NewInf = int(TakeInf) ? InfX : int(MidX),
00179 NewSup = int(TakeInf) ? int(MidX) : SupX
00180 };
00181 public:
00182 enum { ret = meta_sqrt<Y,NewInf,NewSup>::ret };
00183 };
00184
00185 template<int Y, int InfX, int SupX>
00186 class meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
00187
00189 template<typename T, typename U> struct scalar_product_traits
00190 {
00191 enum { Defined = 0 };
00192 };
00193
00194 template<typename T> struct scalar_product_traits<T,T>
00195 {
00196 enum {
00197
00198 Defined = 1
00199 };
00200 typedef T ReturnType;
00201 };
00202
00203 template<typename T> struct scalar_product_traits<T,std::complex<T> >
00204 {
00205 enum {
00206
00207 Defined = 1
00208 };
00209 typedef std::complex<T> ReturnType;
00210 };
00211
00212 template<typename T> struct scalar_product_traits<std::complex<T>, T>
00213 {
00214 enum {
00215
00216 Defined = 1
00217 };
00218 typedef std::complex<T> ReturnType;
00219 };
00220
00221
00222
00223
00224
00225
00226
00227 template<typename T> struct is_diagonal
00228 { enum { ret = false }; };
00229
00230 template<typename T> struct is_diagonal<DiagonalBase<T> >
00231 { enum { ret = true }; };
00232
00233 template<typename T> struct is_diagonal<DiagonalWrapper<T> >
00234 { enum { ret = true }; };
00235
00236 template<typename T, int S> struct is_diagonal<DiagonalMatrix<T,S> >
00237 { enum { ret = true }; };
00238
00239 }
00240
00241 }
00242
00243 #endif // EIGEN_META_H