Meta.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_META_H
00027 #define EIGEN_META_H
00028 
00029 namespace internal {
00030 
00038 struct true_type {  enum { value = 1 }; };
00039 struct false_type { enum { value = 0 }; };
00040 
00041 template<bool Condition, typename Then, typename Else>
00042 struct conditional { typedef Then type; };
00043 
00044 template<typename Then, typename Else>
00045 struct conditional <false, Then, Else> { typedef Else type; };
00046 
00047 template<typename T, typename U> struct is_same { enum { value = 0 }; };
00048 template<typename T> struct is_same<T,T> { enum { value = 1 }; };
00049 
00050 template<typename T> struct remove_reference { typedef T type; };
00051 template<typename T> struct remove_reference<T&> { typedef T type; };
00052 
00053 template<typename T> struct remove_pointer { typedef T type; };
00054 template<typename T> struct remove_pointer<T*> { typedef T type; };
00055 template<typename T> struct remove_pointer<T*const> { typedef T type; };
00056 
00057 template <class T> struct remove_const { typedef T type; };
00058 template <class T> struct remove_const<const T> { typedef T type; };
00059 template <class T> struct remove_const<const T[]> { typedef T type[]; };
00060 template <class T, unsigned int Size> struct remove_const<const T[Size]> { typedef T type[Size]; };
00061 
00062 template<typename T> struct remove_all { typedef T type; };
00063 template<typename T> struct remove_all<const T>   { typedef typename remove_all<T>::type type; };
00064 template<typename T> struct remove_all<T const&>  { typedef typename remove_all<T>::type type; };
00065 template<typename T> struct remove_all<T&>        { typedef typename remove_all<T>::type type; };
00066 template<typename T> struct remove_all<T const*>  { typedef typename remove_all<T>::type type; };
00067 template<typename T> struct remove_all<T*>        { typedef typename remove_all<T>::type type; };
00068 
00069 template<typename T> struct is_arithmetic      { enum { value = false }; };
00070 template<> struct is_arithmetic<float>         { enum { value = true }; };
00071 template<> struct is_arithmetic<double>        { enum { value = true }; };
00072 template<> struct is_arithmetic<long double>   { enum { value = true }; };
00073 template<> struct is_arithmetic<bool>          { enum { value = true }; };
00074 template<> struct is_arithmetic<char>          { enum { value = true }; };
00075 template<> struct is_arithmetic<signed char>   { enum { value = true }; };
00076 template<> struct is_arithmetic<unsigned char> { enum { value = true }; };
00077 template<> struct is_arithmetic<signed short>  { enum { value = true }; };
00078 template<> struct is_arithmetic<unsigned short>{ enum { value = true }; };
00079 template<> struct is_arithmetic<signed int>    { enum { value = true }; };
00080 template<> struct is_arithmetic<unsigned int>  { enum { value = true }; };
00081 template<> struct is_arithmetic<signed long>   { enum { value = true }; };
00082 template<> struct is_arithmetic<unsigned long> { enum { value = true }; };
00083 template<> struct is_arithmetic<signed long long>   { enum { value = true }; };
00084 template<> struct is_arithmetic<unsigned long long> { enum { value = true }; };
00085 
00086 template <typename T> struct add_const { typedef const T type; };
00087 template <typename T> struct add_const<T&> { typedef T& type; };
00088 
00089 template <typename T> struct is_const { enum { value = 0 }; };
00090 template <typename T> struct is_const<T const> { enum { value = 1 }; };
00091 
00092 template<typename T> struct add_const_on_value_type            { typedef const T type;  };
00093 template<typename T> struct add_const_on_value_type<T&>        { typedef T const& type; };
00094 template<typename T> struct add_const_on_value_type<T*>        { typedef T const* type; };
00095 template<typename T> struct add_const_on_value_type<T* const>  { typedef T const* const type; };
00096 template<typename T> struct add_const_on_value_type<T const* const>  { typedef T const* const type; };
00097 
00101 template<bool Condition, typename T> struct enable_if;
00102 
00103 template<typename T> struct enable_if<true,T>
00104 { typedef T type; };
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     // note that the following indirection is needed for gcc-3.3
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     // note that the following indirection is needed for gcc-3.3
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                                 // use ?: instead of || just to shut up a stupid gcc 4.3 warning
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 template<typename T> struct scalar_product_traits<T,T>
00192 {
00193   //enum { Cost = NumTraits<T>::MulCost };
00194   typedef T ReturnType;
00195 };
00196 
00197 template<typename T> struct scalar_product_traits<T,std::complex<T> >
00198 {
00199   //enum { Cost = 2*NumTraits<T>::MulCost };
00200   typedef std::complex<T> ReturnType;
00201 };
00202 
00203 template<typename T> struct scalar_product_traits<std::complex<T>, T>
00204 {
00205   //enum { Cost = 2*NumTraits<T>::MulCost  };
00206   typedef std::complex<T> ReturnType;
00207 };
00208 
00209 // FIXME quick workaround around current limitation of result_of
00210 // template<typename Scalar, typename ArgType0, typename ArgType1>
00211 // struct result_of<scalar_product_op<Scalar>(ArgType0,ArgType1)> {
00212 // typedef typename scalar_product_traits<typename remove_all<ArgType0>::type, typename remove_all<ArgType1>::type>::ReturnType type;
00213 // };
00214 
00215 template<typename T> struct is_diagonal
00216 { enum { ret = false }; };
00217 
00218 template<typename T> struct is_diagonal<DiagonalBase<T> >
00219 { enum { ret = true }; };
00220 
00221 template<typename T> struct is_diagonal<DiagonalWrapper<T> >
00222 { enum { ret = true }; };
00223 
00224 template<typename T, int S> struct is_diagonal<DiagonalMatrix<T,S> >
00225 { enum { ret = true }; };
00226 
00227 } // end namespace internal
00228 
00229 #endif // EIGEN_META_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:59