00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef TVMET_BINARY_FUNCTIONAL_H
00025 #define TVMET_BINARY_FUNCTIONAL_H
00026
00027 namespace tvmet {
00028
00029
00037 template <class T1, class T2>
00038 struct Fcnl_assign : public BinaryFunctional {
00039 static inline
00040 void apply_on(T1& _tvmet_restrict lhs, T2 rhs) {
00041 lhs = static_cast<T1>(rhs);
00042 }
00043
00044 static
00045 void print_xpr(std::ostream& os, std::size_t l=0) {
00046 os << IndentLevel(l) << "fcnl_assign<T1="
00047 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"
00048 << std::endl;
00049 }
00050 };
00051
00052
00063 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00064 template <class T1, class T2> \
00065 struct Fcnl_##NAME : public BinaryFunctional { \
00066 typedef void value_type; \
00067 \
00068 static inline \
00069 void apply_on(T1& _tvmet_restrict lhs, T2 rhs) { \
00070 lhs OP rhs; \
00071 } \
00072 \
00073 static \
00074 void print_xpr(std::ostream& os, std::size_t l=0) { \
00075 os << IndentLevel(l) \
00076 << "Fcnl_" << #NAME << "<T1=" \
00077 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
00078 << std::endl; \
00079 } \
00080 };
00081
00082 TVMET_IMPLEMENT_MACRO(add_eq, +=)
00083 TVMET_IMPLEMENT_MACRO(sub_eq, -=)
00084 TVMET_IMPLEMENT_MACRO(mul_eq, *=)
00085 TVMET_IMPLEMENT_MACRO(div_eq, /=)
00086 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
00087 TVMET_IMPLEMENT_MACRO(xor_eq, ^=)
00088 TVMET_IMPLEMENT_MACRO(and_eq, &=)
00089 TVMET_IMPLEMENT_MACRO(or_eq, |=)
00090 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
00091 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
00092
00093 #undef TVMET_IMPLEMENT_MACRO
00094
00095
00106 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00107 template <class T1, class T2> \
00108 struct Fcnl_##NAME : public BinaryFunctional { \
00109 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
00110 \
00111 static inline \
00112 value_type apply_on(T1 lhs, T2 rhs) { \
00113 return lhs OP rhs; \
00114 } \
00115 \
00116 static \
00117 void print_xpr(std::ostream& os, std::size_t l=0) { \
00118 os << IndentLevel(l) \
00119 << "Fcnl_" << #NAME << "<T1=" \
00120 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
00121 << std::endl; \
00122 } \
00123 };
00124
00125 TVMET_IMPLEMENT_MACRO(add, +)
00126 TVMET_IMPLEMENT_MACRO(sub, -)
00127 TVMET_IMPLEMENT_MACRO(mul, *)
00128 TVMET_IMPLEMENT_MACRO(div, /)
00129 TVMET_IMPLEMENT_MACRO(mod, %)
00130 TVMET_IMPLEMENT_MACRO(bitxor, ^)
00131 TVMET_IMPLEMENT_MACRO(bitand, &)
00132 TVMET_IMPLEMENT_MACRO(bitor, |)
00133 TVMET_IMPLEMENT_MACRO(shl, <<)
00134 TVMET_IMPLEMENT_MACRO(shr, >>)
00135
00136 #undef TVMET_IMPLEMENT_MACRO
00137
00138
00147 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00148 template <class T1, class T2> \
00149 struct Fcnl_##NAME : public BinaryFunctional { \
00150 typedef bool value_type; \
00151 \
00152 static inline \
00153 bool apply_on(T1 lhs, T2 rhs) { \
00154 return lhs OP rhs; \
00155 } \
00156 \
00157 static \
00158 void print_xpr(std::ostream& os, std::size_t l=0) { \
00159 os << IndentLevel(l) \
00160 << "Fcnl_" << #NAME << "<T1=" \
00161 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
00162 << std::endl; \
00163 } \
00164 };
00165
00166 TVMET_IMPLEMENT_MACRO(greater, >)
00167 TVMET_IMPLEMENT_MACRO(less, <)
00168 TVMET_IMPLEMENT_MACRO(greater_eq, >=)
00169 TVMET_IMPLEMENT_MACRO(less_eq, <=)
00170 TVMET_IMPLEMENT_MACRO(eq, ==)
00171 TVMET_IMPLEMENT_MACRO(not_eq, !=)
00172 TVMET_IMPLEMENT_MACRO(and, &&)
00173 TVMET_IMPLEMENT_MACRO(or, ||)
00174
00175 #undef TVMET_IMPLEMENT_MACRO
00176
00177
00181 #define TVMET_IMPLEMENT_MACRO(NAME) \
00182 template <class T1, class T2> \
00183 struct Fcnl_##NAME : public BinaryFunctional { \
00184 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
00185 \
00186 static inline \
00187 value_type apply_on(T1 lhs, T2 rhs) { \
00188 return TVMET_STD_SCOPE(NAME)(lhs, rhs); \
00189 } \
00190 \
00191 static \
00192 void print_xpr(std::ostream& os, std::size_t l=0) { \
00193 os << IndentLevel(l) \
00194 << "Fcnl_" << #NAME << "<T1=" \
00195 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
00196 << std::endl; \
00197 } \
00198 };
00199
00200 TVMET_IMPLEMENT_MACRO(atan2)
00201 TVMET_IMPLEMENT_MACRO(fmod)
00202 TVMET_IMPLEMENT_MACRO(pow)
00203
00204 #undef TVMET_IMPLEMENT_MACRO
00205
00206
00207 #define TVMET_IMPLEMENT_MACRO(NAME) \
00208 template <class T1, class T2> \
00209 struct Fcnl_##NAME : public BinaryFunctional { \
00210 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
00211 \
00212 static inline \
00213 value_type apply_on(T1 lhs, T2 rhs) { \
00214 return TVMET_GLOBAL_SCOPE(NAME)(lhs, rhs); \
00215 } \
00216 \
00217 static \
00218 void print_xpr(std::ostream& os, std::size_t l=0) { \
00219 os << IndentLevel(l) \
00220 << "Fcnl_" << #NAME << "<T1=" \
00221 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
00222 << std::endl; \
00223 } \
00224 };
00225
00226 #if defined(TVMET_HAVE_DREM)
00227
00228 TVMET_IMPLEMENT_MACRO(drem)
00229 #endif
00230
00231 #if defined(TVMET_HAVE_HYPOT)
00232
00233 TVMET_IMPLEMENT_MACRO(hypot)
00234 #endif
00235
00236 #if defined(TVMET_HAVE_JN)
00237
00238 TVMET_IMPLEMENT_MACRO(jn)
00239 #endif
00240
00241 #if defined(TVMET_HAVE_YN)
00242
00243 TVMET_IMPLEMENT_MACRO(yn)
00244 #endif
00245
00246 #undef TVMET_IMPLEMENT_MACRO
00247
00248
00249 #if defined(TVMET_HAVE_COMPLEX)
00250
00254 template <class T1, class T2> struct Fcnl_polar : public BinaryFunctional { };
00255
00256
00264 template <class T>
00265 struct Fcnl_polar<T,T> : public BinaryFunctional {
00266 typedef std::complex<T> value_type;
00267
00268 static inline
00269 value_type apply_on(T lhs, T rhs) {
00270 return std::polar(lhs, rhs);
00271 }
00272
00273 static
00274 void print_xpr(std::ostream& os, std::size_t l=0) {
00275 os << IndentLevel(l) << "Fcnl_polar<T1="
00276 << typeid(T).name() << ", T2=" << typeid(T).name() << ">,"
00277 << std::endl;
00278 }
00279 };
00280 #endif // defined(TVMET_HAVE_COMPLEX)
00281
00282
00287 template <class T1, class T2>
00288 struct Fcnl_swap : public BinaryFunctional {
00289 static inline
00290 void apply_on(T1& _tvmet_restrict lhs, T2& _tvmet_restrict rhs) {
00291 typedef typename PromoteTraits<T1, T2>::value_type temp_type;
00292
00293 temp_type temp(lhs);
00294 lhs = static_cast<T1>(rhs);
00295 rhs = static_cast<T2>(temp);
00296 }
00297
00298 static
00299 void print_xpr(std::ostream& os, std::size_t l=0) {
00300 os << IndentLevel(l) << "Fcnl_swap<T1="
00301 << typeid(T1).name() << ", T2" << typeid(T2).name() << ">,"
00302 << std::endl;
00303 }
00304 };
00305
00306
00307 }
00308
00309 #endif // TVMET_BINARY_FUNCTIONAL_H
00310
00311
00312
00313
00314