27 #ifndef SCHNEK_ARREXPRESSION_H_ 28 #define SCHNEK_ARREXPRESSION_H_ 41 template<
class Operator,
int Length>
42 class ArrayExpression {
49 typedef typename Operator::value_type value_type;
51 static const int length = Length;
63 template<
template<
int>
class CheckingPolicy>
89 template<
class Exp1,
class OperatorType>
95 typedef typename OperatorType::value_type value_type;
107 value_type
operator[](
int i)
const {
return OperatorType::apply(A[i]); }
115 template<
class Exp1,
class Exp2,
class OperatorType>
123 typedef typename OperatorType::value_type value_type;
135 value_type
operator[](
int i)
const {
return OperatorType::apply(A[i], B[i]); }
143 typedef T value_type;
145 value_type
operator[](
int i)
const {
return val; }
152 typedef T value_type;
155 static value_type
apply(value_type x, value_type y) {
return x+y; }
162 typedef T value_type;
165 static value_type
apply(value_type x, value_type y) {
return x-y; }
172 typedef T value_type;
175 static value_type
apply(value_type x, value_type y) {
return x*y; }
182 typedef T value_type;
185 static value_type
apply(value_type x, value_type y) {
return x/y; }
192 typedef T value_type;
195 static value_type
apply(value_type x) {
return x; }
202 typedef T value_type;
205 static value_type
apply(value_type x) {
return -x; }
217 #define EXPR_EXPR(op, symbol) \ 218 template<class exp1, class exp2, int length> \ 221 ArrayExpression<exp1, length>, \ 222 ArrayExpression<exp2, length>, \ 223 op<typename exp1::value_type> \ 228 const ArrayExpression<exp1, length> &A, \ 229 const ArrayExpression<exp2, length> &B) \ 231 typedef ArrayBinaryOp \ 233 ArrayExpression<exp1, length>, \ 234 ArrayExpression<exp2, length>, \ 235 op<typename exp1::value_type> \ 238 return ArrayExpression<OperatorType, length>(OperatorType(A,B)); \ 243 #define ARR_ARR(op, symbol) \ 247 template<int> class CheckingPolicy1, \ 248 template<int> class CheckingPolicy2 \ 252 ArrayExpression< Array<T,length,CheckingPolicy1>, length >, \ 253 ArrayExpression< Array<T,length,CheckingPolicy2>, length >, \ 259 const Array<T,length,CheckingPolicy1> &A, \ 260 const Array<T,length,CheckingPolicy2> &B \ 263 typedef ArrayBinaryOp< \ 264 ArrayExpression< Array<T,length,CheckingPolicy1>, length >, \ 265 ArrayExpression< Array<T,length,CheckingPolicy2>, length >, \ 269 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 273 #define EXPR_ARR(op, symbol) \ 278 template<int> class CheckingPolicy \ 282 ArrayExpression<exp, length>, \ 283 ArrayExpression< Array<T,length,CheckingPolicy>, length >, \ 289 const ArrayExpression<exp, length> &A, \ 290 const Array<T,length,CheckingPolicy> &B \ 293 typedef ArrayBinaryOp< \ 294 ArrayExpression<exp, length>, \ 295 ArrayExpression< Array<T,length,CheckingPolicy>, length >, \ 299 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 304 #define ARR_EXPR(op, symbol) \ 309 template<int> class CheckingPolicy \ 313 ArrayExpression< Array<T,length,CheckingPolicy>, length >, \ 314 ArrayExpression<exp, length>, \ 320 const Array<T,length,CheckingPolicy> &A, \ 321 const ArrayExpression<exp, length> &B \ 324 typedef ArrayBinaryOp< \ 325 ArrayExpression< Array<T,length,CheckingPolicy>, length >, \ 326 ArrayExpression<exp, length>, \ 330 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 334 #define SCAL_EXPR(op, symbol) \ 335 template<class T, class exp, int length> \ 338 ArrayConstantExp<T>, \ 339 ArrayExpression<exp, length>, \ 344 operator symbol (const T &A, const ArrayExpression<exp, length> &B) \ 346 typedef ArrayBinaryOp< \ 347 ArrayConstantExp<T>, \ 348 ArrayExpression<exp, length>, \ 352 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 356 #define EXPR_SCAL(op, symbol) \ 357 template<class T, class exp, int length> \ 360 ArrayExpression<exp, length>, \ 361 ArrayConstantExp<T>, \ 366 operator symbol (const ArrayExpression<exp, length> &A, const T &B) \ 368 typedef ArrayBinaryOp< \ 369 ArrayExpression<exp, length>, \ 370 ArrayConstantExp<T>, \ 374 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 377 #define SCAL_ARR(op, symbol) \ 378 template<class T, int length, template<int> class CheckingPolicy> \ 381 ArrayConstantExp<T>, \ 382 Array<T,length,CheckingPolicy>, \ 387 operator symbol (const T &A, const Array<T,length,CheckingPolicy> &B) \ 389 typedef ArrayBinaryOp< \ 390 ArrayConstantExp<T>, \ 391 Array<T,length,CheckingPolicy>, \ 395 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 399 #define ARR_SCAL(op, symbol) \ 400 template<class T, int length, template<int> class CheckingPolicy> \ 403 Array<T,length,CheckingPolicy>, \ 404 ArrayConstantExp<T>, \ 409 operator symbol (const Array<T,length,CheckingPolicy> &A, const T &B) \ 411 typedef ArrayBinaryOp< \ 412 Array<T,length,CheckingPolicy>, \ 413 ArrayConstantExp<T>, \ 417 return ArrayExpression<OperatorType, length> (OperatorType(A,B)); \ 421 #define UNARY_ARR(op, symbol) \ 425 template<int> class CheckingPolicy1 \ 429 ArrayExpression< Array<T,length,CheckingPolicy1>, length >, \ 435 const Array<T,length,CheckingPolicy1> &A \ 438 typedef ArrayUnaryOp< \ 439 ArrayExpression< Array<T,length,CheckingPolicy1>, length >, \ 443 return ArrayExpression<OperatorType, length> (OperatorType(A)); \ 448 #define UNARY_EXPR(op, symbol) \ 453 template<int> class CheckingPolicy \ 457 ArrayExpression<exp, length>, \ 463 const ArrayExpression<exp, length> &A \ 466 typedef ArrayUnaryOp< \ 467 ArrayExpression<exp, length>, \ 471 return ArrayExpression<OperatorType, length> (OperatorType(A)); \ 544 template<
class T,
int length,
template <
int>
class CheckingPolicy>
545 template<
class Operator>
548 for (
int i=0; i<length; ++i)
553 template<
class T,
int length,
template <
int>
class CheckingPolicy>
554 template<
class Operator>
557 for (
int i=0; i<length; ++i)
562 template<
class T,
int length,
template <
int>
class CheckingPolicy>
563 template<
class Operator>
566 for (
int i=0; i<length; ++i)
571 template<
class T,
int length,
template <
int>
class CheckingPolicy>
572 template<
class Operator>
575 for (
int i=0; i<length; ++i)
580 template<
class T,
int length,
template <
int>
class CheckingPolicy>
581 template<
class Operator>
584 for (
int i=0; i<length; ++i)
591 template<
class T,
int length,
template <
int>
class CheckingPolicy>
592 template<
class Operator>
595 for (
int i=0; i<length; ++i)
600 #endif // SCHNEK_ARRAYEXPRESSION_H_ ArrayUnaryOp(const ArrayUnaryOp &Op)
Definition: arrayexpression.hpp:101
Array< T, length, CheckingPolicy > & operator-=(const Array< T2, length, CheckingPolicy2 > &)
value_type operator[](int i) const
Definition: arrayexpression.hpp:76
ArrayExpression(const Operator Op_)
Definition: arrayexpression.hpp:54
ArrayBinaryOp(const ArrayBinaryOp &Op)
Definition: arrayexpression.hpp:129
Definition: operators2.hpp:34
static value_type apply(value_type x, value_type y)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:165
Array()
The default constructor.
Array< T, length, CheckingPolicy > & operator*=(const Array< T2, length, CheckingPolicy2 > &)
static value_type apply(value_type x, value_type y)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:185
Definition: arrayexpression.hpp:161
ArrayBinaryOp(const Exp1 &A_, const Exp2 &B_)
Definition: arrayexpression.hpp:126
static value_type apply(value_type x, value_type y)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:175
Definition: arrayexpression.hpp:139
Definition: arrayexpression.hpp:171
static value_type apply(value_type x)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:195
Definition: arrayexpression.hpp:116
value_type operator[](int i) const
Definition: arrayexpression.hpp:107
Definition: arrayexpression.hpp:151
static value_type apply(value_type x, value_type y)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:155
Definition: arrayexpression.hpp:90
Array< T, length, CheckingPolicy > & operator+=(const Array< T2, length, CheckingPolicy2 > &)
Array< T, length, CheckingPolicy > & operator=(const Array< T2, length, CheckingPolicy2 > &)
static value_type apply(value_type x)
Returns the sum of the two elements.
Definition: arrayexpression.hpp:205
Definition: arrayexpression.hpp:201
ArrayExpression(const ArrayExpression &Expr)
Definition: arrayexpression.hpp:57
ArrayUnaryOp(const Exp1 &A_)
Definition: arrayexpression.hpp:98
value_type operator[](int i) const
Definition: arrayexpression.hpp:135
Definition: arrayexpression.hpp:181
Array< T, length, CheckingPolicy > & operator/=(const Array< T2, length, CheckingPolicy2 > &)
Definition: arrayexpression.hpp:191