aimstil  5.0.5
TExprOperators.h
Go to the documentation of this file.
1 #ifndef TIL_TEXPR_OPERATORS_H
2 #define TIL_TEXPR_OPERATORS_H
3 
5 // TODO: put package files (i.e. files that should not be included directly by library
6 // users, but that are only included inside the library by the package it belongs to) in
7 // a separate physical folder, so that the user is not overwhelmed with include files
8 // when looking at the directory...
9 
10 namespace til { namespace expr {
11 
12  //-------------------//
13  // Unary operators //
14  //-------------------//
15 
16 #define TIL_DEFINITION_UNARY_OPERATOR_EXPRS(opName, functor) \
17  template < typename Expr > \
18  inline \
19  TExpr< TExprUnaryOperator< Expr, functor > > \
20  opName ( const TExpr<Expr> &e) \
21  { \
22  typedef TExprUnaryOperator< Expr, functor > TExprRet; \
23  return TExpr<TExprRet>(TExprRet(e.getExpr(), functor ())); \
24  } \
25 
29 
30 #undef TIL_DEFINITION_UNARY_OPERATOR_EXPRS
31 
32 
33  //-------------------------------//
34  // Binary operators with values //
35  //-------------------------------//
36 
37 
38 #define TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(opName, functor) \
39 template < typename Expr, typename T > \
40 inline \
41 TExpr< TExprBinaryOperator< Expr, TExprConstant<T>, functor > > \
42 opName ( const TExpr<Expr> & e, const T & value ) \
43 { \
44 typedef TExprBinaryOperator<Expr, TExprConstant<T>, functor > TExprRet; \
45 return TExpr<TExprRet>(TExprRet(e.getExpr(), TExprConstant<T>(value), functor())); \
46 }
47 
48 #define TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_RIGHT(opName, functor) \
49 template < typename Expr, typename T > \
50 inline \
51 TExpr< TExprBinaryOperator< TExprConstant<T>, Expr, functor > > \
52 opName ( const T & value, const TExpr<Expr> & e ) \
53 { \
54 typedef TExprBinaryOperator<TExprConstant<T>, Expr, functor > TExprRet; \
55 return TExpr<TExprRet>(TExprRet(TExprConstant<T>(value), e.getExpr(), functor())); \
56 }
57 
58 #define TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE(opName, functor) \
59 TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(opName, functor) \
60 TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_RIGHT(opName, functor)
61 
70 
71 /*
72  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator+, functor::Plus);
73  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator-, functor::Minus);
74  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator*, functor::Multiplies);
75  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator/, functor::Divides);
76  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator<, functor::Less);
77  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator<=, functor::Less_Equal);
78  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator==, functor::Equal_To);
79  TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT(operator!=, functor::Not_Equal_To);
80 */
81 
82 #undef TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_LEFT
83 #undef TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE_RIGHT
84 #undef TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE
85 
86  //----------------------------------//
87  // Binary operators between TExpr //
88 //----------------------------------//
89 
90 #define TIL_DEFINITION_BINARY_OPERATOR_EXPRS(opName, functor) \
91 template < typename Expr1, typename Expr2 > \
92 inline \
93 TExpr< TExprBinaryOperator< Expr1, Expr2, functor > > \
94 opName ( const TExpr<Expr1> &e1, const TExpr<Expr2> &e2) \
95 { \
96 typedef TExprBinaryOperator<Expr1, Expr2, functor > TExprRet; \
97 return TExpr<TExprRet>(TExprRet(e1.getExpr(), e2.getExpr(), functor())); \
98 }
99 
108 
109  // NB: ?= assign-operators are defined inside TExpr class
110  //TIL_DEFINITION_BINARY_OPERATOR_EXPRS(operator+=, functor::AddTo);
111 
112 #undef TIL_DEFINITION_BINARY_OPERATOR_EXPRS
113 
114 
116  template < typename Expr1, typename Expr2 >
117  TExpr<TExprCouple<Expr1, Expr2> >
119  const TExpr<Expr1> &e1,
120  const TExpr<Expr2> &e2
121  )
122  {
123  typedef TExprCouple<Expr1, Expr2> TExprRet;
124  return TExpr<TExprRet>(TExprRet(e1.getExpr(), e2.getExpr()));
125  }
126 
127 
128 }} // namespace til::expr
129 
130 #endif
131 
DetemplateOperator1< std::not_equal_to > Not_Equal_To
TIL_DEFINITION_BINARY_OPERATOR_EXPR_VALUE(operator+, functor::Plus)
TIL_DEFINITION_BINARY_OPERATOR_EXPRS(operator+, functor::Plus)
DetemplateOperator2< DefaultThird< til::functor::Div >::type > Divides
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
DetemplateOperator1< std::less > Less
A wrapper class of a template expression.
Definition: TExpr.h:128
DetemplateOperator2< DefaultThird< til::functor::Add >::type > Plus
DetemplateOperator1< til::functor::Abs > Abs
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
DetemplateOperator2< DefaultThird< til::functor::Sub >::type > Minus
TIL_DEFINITION_UNARY_OPERATOR_EXPRS(operator-, functor::Negate)
DetemplateOperator1< std::less_equal > Less_Equal
TExpr< TExprCouple< Expr1, Expr2 > > operator,(const TExpr< Expr1 > &e1, const TExpr< Expr2 > &e2)
Sequential evaluation of two template expressions.
DetemplateOperator1< std::negate > Negate
DetemplateOperator1< std::equal_to > Equal_To
DetemplateOperator1< til::functor::Deref > Deref
Evaluate one expression and then the other.
DetemplateOperator2< DefaultThird< til::functor::Mul >::type > Multiplies
const Expr & getExpr() const
Definition: TExpr.h:142