aimstil  5.0.5
TExprFunctions.h
Go to the documentation of this file.
1 #ifndef TIL_TEXPR_FUNCTIONS_H
2 #define TIL_TEXPR_FUNCTIONS_H
3 
4 
7 
8 namespace til { namespace expr {
9 
10 
12  // TODO: put some checking in there. One could check that
13  // the return type of the first expression is a bool. One could
14  template < typename ExprIf, typename ExprThen >
15 // The following don't work, because void::value_type is not defined, but if we
16 // want TEXpr to work even for non-iteratos, we would just have to use
17 // traits for iterator types (probably endemic to TExpr only, so we can put
18 // that in traits), and never use Iterator::value_type but value_type<Iterator>
19 // that would be defined for numeric types as well (or rather pointers on
20 // numeric types). To do that we need to have an IsIteratorType I guess
21 // enable_if<are_same_types<bool, typename ExprIf::TypeStruct<void,void,void>::Type>,
22  TExpr<TExprIfThen<ExprIf, ExprThen> >
23 // >
25  const TExpr<ExprIf> &eIf,
26  const TExpr<ExprThen> &eThen
27  )
28  {
29  typedef TExprIfThen<ExprIf, ExprThen> TExprRet;
30  return TExpr<TExprRet>(TExprRet(eIf.getExpr(), eThen.getExpr()));
31  }
32 
34  template < typename ExprIf, typename ExprThen, typename ExprElse >
37  const TExpr<ExprIf> &eIf,
38  const TExpr<ExprThen> &eThen,
39  const TExpr<ExprElse> &eElse
40  )
41  {
43  return TExpr<TExprRet>(TExprRet(eIf.getExpr(), eThen.getExpr(), eElse.getExpr()));
44  }
45 
46 
48  template < typename Expr >
49  //TExpr<TExprSqrt<Expr> >
51  sqrt(const TExpr<Expr> &e)
52  {
54  return TExpr<TExprRet>(TExprRet(e.getExpr(), functor::Sqrt()));
55  }
56 
57  // dunno why, but this one cannot be in this namespace...
58  /*
60  template < typename TTo, typename Expr >
61  inline
62  TExpr<TExprUnaryOperator< Expr, functor::Cast<TTo> > >
63  cast (const TExpr<Expr> &e)
64  {
65  typedef TExprUnaryOperator<Expr, functor::Cast<TTo> > TExprRet;
66  return TExpr<TExprRet>(TExprRet(e.getExpr(), functor::Cast<TTo>()));
67  }
68  */
69 
71  template < typename T >
73  var(T & lvalue)
74  {
75  return TExpr<TExprLValue<T> >(TExprLValue<T>(lvalue));
76  }
77 
78  template < typename TFunctor >
79  typename boost::enable_if<
80  is_detemplated_functor<TFunctor>,
82  >::type
83  func(TFunctor & f)
84  {
86  }
87 
88  template < typename TFunctor >
89  typename boost::disable_if<
90  is_detemplated_functor<TFunctor>,
92  >::type
93  func(TFunctor & f)
94  {
96  }
97 
98  /*
99 
101  template < typename TFunctor, typename Expr>
102  typename boost::enable_if<
103  is_detemplated_functor<TFunctor>
104  ,
105  expr::TExpr<expr::TExprUnaryOperator<Expr, TFunctor> >
106  >::type
107  bind(TFunctor & functor, const expr::TExpr<Expr> & e)
108  {
109  typedef expr::TExprUnaryOperator<Expr, TFunctor> TExprRet;
110  return expr::TExpr<TExprRet>(TExprRet(e.getExpr(), functor));
111  }
112 
114  // NB: e is const, (1) because it can: we make copy and return a different functor
115  // anyway, (2) because it must: bind should accept const texpr such as placeholders.
116  template < typename TFunctor, typename Expr>
117  typename boost::disable_if<
118  is_detemplated_functor<TFunctor>
119  ,
120  expr::TExpr<expr::TExprUnaryOperator<Expr, expr::functor::Wrap<TFunctor> > >
121  >::type
122  bind(TFunctor & functor, const expr::TExpr<Expr> & e)
123  {
124  typedef expr::TExprUnaryOperator<Expr, expr::functor::Wrap<TFunctor> > TExprRet;
125  return expr::TExpr<TExprRet>(TExprRet(e.getExpr(), expr::functor::Wrap<TFunctor>(functor)));
126  }
127  */
128 
130  template < typename TTo, typename Expr >
131  inline
133  cast (const TExpr<Expr> &e)
134  {
136  return TExpr<TExprRet>(TExprRet(e.getExpr(), functor::Cast<TTo>()));
137  }
138 
139 
140  template < typename Expr1, typename Expr2 >
141  inline
144  {
146  return TExpr<TExprRet>(TExprRet(e1.getExpr(), e2.getExpr(), functor::CastTo()));
147  }
148 
149  }// namespace expr
150 
151 } // namespace til
152 
153 #endif
154 
Apply a binary numerical functor to two template expressions.
boost::enable_if< is_detemplated_functor< TFunctor >, expr::TExprFunctorHelper< TFunctor > >::type func(TFunctor &f)
If/then block using template expressions.
DetemplateOperator2< til::functor::CastTo > CastTo
TExpr< TExprIfThen< ExprIf, ExprThen > > if_then(const TExpr< ExprIf > &eIf, const TExpr< ExprThen > &eThen)
if/then block for expressions
DetemplateOperator1< til::functor::Sqrt > Sqrt
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
TExpr< TExprBinaryOperator< Expr1, Expr2, functor::CastTo > > castTo(TExpr< Expr1 > e1, TExpr< Expr2 > e2)
If/then block using template expressions.
A wrapper class of a template expression.
Definition: TExpr.h:128
A template expression class for left-values.
Definition: TExpr.h:256
TExpr< TExprIfThenElse< ExprIf, ExprThen, ExprElse > > if_then_else(const TExpr< ExprIf > &eIf, const TExpr< ExprThen > &eThen, const TExpr< ExprElse > &eElse)
If/then/else structure for template expressions.
Apply a unary numerical functor to a template expression.
TExpr< TExprLValue< T > > var(T &lvalue)
Insert a left value in a template expression.
TExpr< TExprUnaryOperator< Expr, functor::Cast< TTo > > > cast(const TExpr< Expr > &e)
static type casting.
TExpr< TExprUnaryOperator< Expr, functor::Sqrt > > sqrt(const TExpr< Expr > &e)
Square root.
const Expr & getExpr() const
Definition: TExpr.h:142