Developer documentation

texp_operators.hpp
Go to the documentation of this file.
1 #ifndef realroot_ARITHM_TEXP_OPERATORS_H
2 #define realroot_ARITHM_TEXP_OPERATORS_H
3 
6 
7 namespace mmx {
8 
9 #define define_binary_operator_structure(opname,function,call) \
10  \
11 struct opname \
12 { \
13  inline static const char * name() { return #call; }; \
14  template < class A, class B, class C > inline \
15  void operator()( A & a, const B & b, const C & c) const \
16  { \
17  call (a, b, c); \
18  }; \
19  template < class A, class B > inline \
20  void operator()( A & a, const B & b ) const \
21  { \
22  call (a, b); \
23  }; \
24 }; \
25 
26 #define define_binary_operator(opname,function,call)\
27 define_binary_operator_structure(opname,function,call)\
28 template<class X, class Y> inline \
29 texp::template_expression< \
30 texp::binary_operator<opname, \
31  texp::template_expression<X>, \
32  texp::template_expression<Y> > > \
33 function( const texp::template_expression<X>& x, \
34  const texp::template_expression<Y>& y ) \
35 { \
36  return texp::template_expression< texp::binary_operator< opname, \
37  texp::template_expression<X>, \
38  texp::template_expression<Y> > > ( x, y ); \
39 }; \
40 \
41 template<class X, class Y> inline \
42 texp::template_expression< \
43 texp::binary_operator<opname, \
44  texp::template_expression<X>, \
45  texp::template_expression<Y> > > \
46 function( const texp::template_expression<X>& x, const Y& y ) \
47 { \
48  return texp::template_expression< texp::binary_operator< opname, \
49  texp::template_expression<X>, \
50  texp::template_expression<Y> > > \
51  ( x, texp::template_expression<Y>(y)); \
52 }; \
53 \
54 template<class X, class Y> inline \
55 texp::template_expression< \
56 texp::binary_operator<opname, \
57  texp::template_expression<X>, \
58  texp::template_expression<Y> > > \
59 function( const X& x, const texp::template_expression<Y>& y ) \
60 { \
61  return \
62  texp::template_expression< texp::binary_operator<opname \
63  , texp::template_expression<X> \
64  , texp::template_expression<Y> > > \
65  (texp::template_expression<X>(x),y); \
66 }; \
67 \
68 template<class X,class Y> \
69 X & call( X & r, const texp::template_expression<Y> & exp ) \
70 { \
71  typename template_expression<Y>::E tmp; \
72  exp.eval(tmp); \
73  call(r,tmp); \
74  return r; \
75 } \
76 
77 #define define_unary_operator(opname,function,call)\
78 \
79 struct opname \
80 { \
81  inline static const char * name() \
82  { \
83  return #call; \
84  }; \
85  \
86  template < class A, class B > inline \
87  void operator()(A & a, const B & b) const \
88  { \
89  call (a, b); \
90  }; \
91  template < class A> inline \
92  void operator()(A & a) const \
93  { \
94  call (a); \
95  }; \
96 }; \
97 \
98 template<class X> inline \
99 texp::template_expression< \
100  unary_operator< opname, \
101  texp::template_expression<X> > > \
102 function( const texp::template_expression<X>& x ) \
103 { \
104  return \
105  texp::template_expression< \
106  unary_operator<opname, texp::template_expression<X> > >( x ); \
107 }; \
108 \
109 template<class X> inline \
110 texp::template_expression< \
111  unary_operator< opname, \
112  texp::template_expression<X> > > \
113 function( const X& x ) \
114 { \
115  return \
116  texp::template_expression< \
117  unary_operator<opname, texp::template_expression<X> > > \
118  ( texp::template_expression<X>(x) ); \
119 }; \
120 
121 #define declare_binary_operator(tp_arg_list,parm0,parm1,opname,function)\
122 tp_arg_list inline \
123 texp::template_expression< texp::binary_operator< opname,\
124 texp::template_expression< parm0 >, \
125 texp::template_expression< parm1 > > > \
126 function( const parm0 & x, const parm1 & y )\
127 { return \
128  texp::template_expression< \
129  texp::binary_operator< \
130  opname, texp::template_expression< parm0 >, texp::template_expression< parm1 > > >\
131  (texp::template_expression< parm0 >(x),texp::template_expression< parm1 >(y));\
132 };\
133 tp_arg_list inline \
134 texp::template_expression< texp::binary_operator< opname , \
135 texp::template_expression< parm0 >,\
136 texp::template_expression< parm1 > > >\
137 function( const texp::template_expression<parm0> & x, const parm1 & y )\
138 { return texp::template_expression< texp::binary_operator< opname, texp::template_expression< parm0 >, texp::template_expression< parm1 > > >\
139  (x,texp::template_expression<parm1>(y)); };\
140 tp_arg_list inline \
141 texp::template_expression< texp::binary_operator< opname , \
142 texp::template_expression< parm0 >, \
143 texp::template_expression< parm1 > > >\
144 function( const parm0 & x, const texp::template_expression<parm1> & y )\
145 { return texp::template_expression< texp::binary_operator< opname, texp::template_expression< parm0 >, texp::template_expression< parm1 > > >\
146 (texp::template_expression< parm0 >(x),y); }
147 
148 #define declare_unary_operator(tp_arg_list,parm,opname,function)\
149 tp_arg_list inline \
150 texp::template_expression< texp::unary_operator< opname, \
151  texp::template_expression<parm> > >\
152 function( const parm& x ) \
153 { \
154  return texp::template_expression<\
155  texp::unary_operator< opname, \
156  texp::template_expression<parm> > >( texp::template_expression<parm>(x) ); \
157 };\
158 
159 
160 }// end namespace mmx
161 
162 #endif
Definition: array.hpp:12
Home