00001 #ifndef VIENNAMATH_RUNTIME_OPERATIONS_CONSTANT_HPP
00002 #define VIENNAMATH_RUNTIME_OPERATIONS_CONSTANT_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ostream>
00021 #include "viennamath/forwards.h"
00022 #include "viennamath/compiletime/promote_traits.hpp"
00023 #include "viennamath/runtime/binary_operators.hpp"
00024
00029 namespace viennamath
00030 {
00031
00033
00035
00036
00038 template <typename ScalarType, typename InterfaceType, typename OtherScalarType, typename RHS>
00039 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType >,
00040 op_plus<typename InterfaceType::numeric_type>,
00041 RHS >
00042 operator+(rt_constant<ScalarType, InterfaceType> const & lhs,
00043 ct_binary_expr<rt_constant<OtherScalarType, InterfaceType>, op_plus<typename InterfaceType::numeric_type>, RHS> const & other)
00044 {
00045 typedef rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType > ret_constant;
00046 return ct_binary_expr<ret_constant,
00047 op_plus<typename InterfaceType::numeric_type>,
00048 RHS
00049 >(ret_constant(static_cast<ScalarType>(lhs) + static_cast<OtherScalarType>(other.lhs())),
00050 other.rhs());
00051 }
00052
00054 template <typename ScalarType, typename InterfaceType, long value, typename RHS>
00055 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType >,
00056 op_plus<typename InterfaceType::numeric_type>,
00057 RHS >
00058 operator+(rt_constant<ScalarType, InterfaceType> const & lhs,
00059 ct_binary_expr<ct_constant<value>, op_plus<typename InterfaceType::numeric_type>, RHS> const & other)
00060 {
00061 typedef rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType > ret_constant;
00062 return ct_binary_expr<ret_constant,
00063 op_plus<typename InterfaceType::numeric_type>,
00064 RHS
00065 >(ret_constant(static_cast<ScalarType>(lhs) + value),
00066 other.rhs());
00067 }
00068
00070 template <typename ScalarType, typename InterfaceType, typename OtherScalarType, typename RHS>
00071 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType >,
00072 op_minus<typename InterfaceType::numeric_type>,
00073 RHS >
00074 operator+(rt_constant<ScalarType, InterfaceType> const & lhs,
00075 ct_binary_expr<rt_constant<OtherScalarType, InterfaceType>, op_minus<typename InterfaceType::numeric_type>, RHS> const & other)
00076 {
00077 typedef rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType > ret_constant;
00078 return ct_binary_expr<ret_constant,
00079 op_minus<typename InterfaceType::numeric_type>,
00080 RHS
00081 >(ret_constant(static_cast<ScalarType>(lhs) + static_cast<OtherScalarType>(other.lhs())),
00082 other.rhs());
00083 }
00084
00086 template <typename ScalarType, typename InterfaceType, long value, typename RHS>
00087 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType >,
00088 op_minus<typename InterfaceType::numeric_type>,
00089 RHS >
00090 operator+(rt_constant<ScalarType, InterfaceType> const & lhs,
00091 ct_binary_expr<ct_constant<value>, op_minus<typename InterfaceType::numeric_type>, RHS> const & other)
00092 {
00093 typedef rt_constant<typename promote_traits<ScalarType, op_plus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType > ret_constant;
00094 return ct_binary_expr<ret_constant,
00095 op_minus<typename InterfaceType::numeric_type>,
00096 RHS
00097 >(ret_constant(static_cast<ScalarType>(lhs) + value),
00098 other.rhs());
00099 }
00100
00101
00103 template <long value, typename RHS, typename ScalarType, typename T, typename InterfaceType>
00104 ct_binary_expr< rt_constant<typename promote_traits<long, op_plus<T>, ScalarType>::result_type >,
00105 op_plus<T>,
00106 RHS >
00107 operator+(ct_binary_expr<ct_constant<value>, op_plus<T>, RHS> const & lhs,
00108 rt_constant<ScalarType, InterfaceType> const & other)
00109 {
00110 typedef rt_constant< typename promote_traits<long, op_plus<T>, ScalarType>::result_type > result_constant;
00111 return ct_binary_expr<result_constant,
00112 op_plus<T>,
00113 RHS >(result_constant(value + static_cast<ScalarType>(other)),
00114 lhs.rhs());
00115 }
00116
00118 template <long value, typename RHS, typename ScalarType, typename InterfaceType>
00119 ct_binary_expr< rt_constant<default_numeric_type, InterfaceType >,
00120 op_minus<default_numeric_type>,
00121 RHS >
00122 operator+(ct_binary_expr<ct_constant<value>, op_minus<default_numeric_type>, RHS> const & lhs,
00123 rt_constant<ScalarType, InterfaceType> const & other)
00124 {
00125 typedef rt_constant<ScalarType, InterfaceType> result_constant;
00126 return ct_binary_expr<result_constant,
00127 op_minus<default_numeric_type>,
00128 RHS >(result_constant(value + other),
00129 lhs.rhs());
00130 }
00131
00132
00133
00135
00137 template <typename ScalarType, typename InterfaceType, typename OtherScalarType, typename RHS>
00138 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType >,
00139 op_minus<typename InterfaceType::numeric_type>,
00140 RHS >
00141 operator-(rt_constant<ScalarType, InterfaceType> const & lhs,
00142 ct_binary_expr<rt_constant<OtherScalarType, InterfaceType>, op_plus<typename InterfaceType::numeric_type>, RHS> const & other)
00143 {
00144 typedef rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType > ret_constant;
00145 return ct_binary_expr<ret_constant,
00146 op_minus<typename InterfaceType::numeric_type>,
00147 RHS
00148 >(ret_constant(static_cast<ScalarType>(lhs) - static_cast<OtherScalarType>(other.lhs())),
00149 other.rhs());
00150 }
00151
00153 template <typename ScalarType, typename InterfaceType, long value, typename RHS>
00154 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType >,
00155 op_minus<typename InterfaceType::numeric_type>,
00156 RHS >
00157 operator-(rt_constant<ScalarType, InterfaceType> const & lhs,
00158 ct_binary_expr<ct_constant<value>, op_plus<typename InterfaceType::numeric_type>, RHS> const & other)
00159 {
00160 typedef rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType > ret_constant;
00161 return ct_binary_expr<ret_constant,
00162 op_minus<typename InterfaceType::numeric_type>,
00163 RHS
00164 >(ret_constant(static_cast<ScalarType>(lhs) - value),
00165 other.rhs());
00166 }
00167
00169 template <typename ScalarType, typename InterfaceType, typename OtherScalarType, typename RHS>
00170 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType >,
00171 op_plus<typename InterfaceType::numeric_type>,
00172 RHS >
00173 operator-(rt_constant<ScalarType, InterfaceType> const & lhs,
00174 ct_binary_expr<rt_constant<OtherScalarType, InterfaceType>, op_minus<typename InterfaceType::numeric_type>, RHS> const & other)
00175 {
00176 typedef rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, OtherScalarType>::result_type, InterfaceType > ret_constant;
00177 return ct_binary_expr<ret_constant,
00178 op_plus<typename InterfaceType::numeric_type>,
00179 RHS
00180 >(ret_constant(static_cast<ScalarType>(lhs) - static_cast<OtherScalarType>(other.lhs())),
00181 other.rhs());
00182 }
00183
00185 template <typename ScalarType, typename InterfaceType, long value, typename RHS>
00186 ct_binary_expr<rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType >,
00187 op_plus<typename InterfaceType::numeric_type>,
00188 RHS >
00189 operator-(rt_constant<ScalarType, InterfaceType> const & lhs,
00190 ct_binary_expr<ct_constant<value>, op_minus<typename InterfaceType::numeric_type>, RHS> const & other)
00191 {
00192 typedef rt_constant<typename promote_traits<ScalarType, op_minus<typename InterfaceType::numeric_type>, long>::result_type, InterfaceType > ret_constant;
00193 return ct_binary_expr<ret_constant,
00194 op_plus<typename InterfaceType::numeric_type>,
00195 RHS
00196 >(ret_constant(static_cast<ScalarType>(lhs) - value),
00197 other.rhs());
00198 }
00199
00200
00201
00203
00205
00206 }
00207
00208 #endif