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
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef SACADO_TRAITS_HPP
00052 #define SACADO_TRAITS_HPP
00053
00054 namespace Sacado {
00055
00057
00061 template <typename A, typename B> struct Promote {};
00062
00064 template <typename A> struct Promote<A,A> {
00065 typedef A type;
00066 };
00067
00069 #define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \
00070 template <> struct Promote< type1, type2 > { \
00071 typedef type3 type; \
00072 }; \
00073 template <> struct Promote< type2, type1 > { \
00074 typedef type3 type; \
00075 };
00076
00077 SACADO_PROMOTE_SPECIALIZATION(double,float,double)
00078 SACADO_PROMOTE_SPECIALIZATION(double,long,double)
00079 SACADO_PROMOTE_SPECIALIZATION(double,int,double)
00080 SACADO_PROMOTE_SPECIALIZATION(float,long,float)
00081 SACADO_PROMOTE_SPECIALIZATION(float,int,float)
00082
00083 #undef SACADO_PROMOTE_SPECIALIZATION
00084
00086
00090 template <typename T> struct ScalarType {};
00091
00093
00097 template <typename T> struct ValueType {};
00098
00100
00104 template <typename T> struct ScalarValueType {};
00105
00107
00111 template <typename T> struct IsADType {};
00112
00114
00118 template <typename T> struct IsScalarType {};
00119
00121
00124 template <typename T> struct Value {};
00125
00127 template <typename T> struct MarkConstant {
00128 static void eval(T& x) {}
00129 };
00130
00132 #define SACADO_BUILTIN_SPECIALIZATION(t) \
00133 template <> struct ScalarType< t > { \
00134 typedef t type; \
00135 }; \
00136 template <> struct ValueType< t > { \
00137 typedef t type; \
00138 }; \
00139 template <> struct ScalarValueType< t > { \
00140 typedef t type; \
00141 }; \
00142 template <> struct IsADType< t > { \
00143 static const bool value = false; \
00144 }; \
00145 template <> struct IsScalarType< t > { \
00146 static const bool value = true; \
00147 }; \
00148 template <> struct Value< t > { \
00149 static const t& eval(const t& x) { return x; } \
00150 };
00151
00152 SACADO_BUILTIN_SPECIALIZATION(char)
00153 SACADO_BUILTIN_SPECIALIZATION(float)
00154 SACADO_BUILTIN_SPECIALIZATION(double)
00155 SACADO_BUILTIN_SPECIALIZATION(int)
00156 SACADO_BUILTIN_SPECIALIZATION(unsigned int)
00157 SACADO_BUILTIN_SPECIALIZATION(long)
00158 SACADO_BUILTIN_SPECIALIZATION(unsigned long)
00159 SACADO_BUILTIN_SPECIALIZATION(bool)
00160
00161 #undef SACADO_BUILTIN_SPECIALIZATION
00162
00163 }
00164
00165 #endif // SACADO_TRAITS_HPP