QDP++
qdp_qdpexpr.h
Go to the documentation of this file.
1// -*- C++ -*-
2
6
7#ifndef QDP_QDPEXPR_H
8#define QDP_QDPEXPR_H
9
10namespace QDP {
11
12
14template<class T, class C>
16{
17public:
19 typedef T Subtype_t;
20
22 typedef T Expression_t;
23
25 typedef C Container_t;
26
28 QDPExpr(const T& expr) : expr_m(expr)
29 { }
30
32 const Expression_t& expression() const
33 {
34 return expr_m;
35 }
36
37#if 0
39 operator C() const
40 {
41 return C(*this);
42 }
43#endif
44
45private:
50
51 T expr_m;
52};
53
54
55//-----------------------------------------------------------------------------
56// For Expressions, we strip the QDPExpr<> wrapper since it is intended
57// to wrap the whole expression. (QDPExpr<Scalar<>>+QDPExpr<BinaryNode<>>
58// becomes QDPExpr<BinaryNode<OpAdd,Scalar<>,BinaryNode<>>>)
59//-----------------------------------------------------------------------------
60
61template<class T, class C>
63{
65 inline static
66 Expression_t make(const T &a) { return Expression_t(a); }
67};
68
69template<class T, class C>
70struct CreateLeaf<QDPExpr<T,C> >
71{
73 typedef typename Input_t::Expression_t Leaf_t;
74
75 inline static
76 const Leaf_t &make(const Input_t& a)
77 {
78 return a.expression();
79 }
80};
81
82
83template<class T, class FTag, class CTag, class DTag>
84struct ForEach<QDPExpr<T,DTag>, FTag, CTag>
85{
87 inline static
88 Type_t apply(const QDPExpr<T,DTag>& expr, const FTag &f,
89 const CTag &c)
90 {
91 return ForEach<T, FTag, CTag>::apply(expr.expression(), f, c);
92 }
93};
94
95
96//-----------------------------------------------------------------------------
97// Alternative OpCombiner's that deal explicitly with references
98//-----------------------------------------------------------------------------
99
100template<class A,class Op>
102{
104 inline static
105 Type_t combine(Reference<A> a, Op op, OpCombine) { return op(a.reference()); }
106};
107
108template<class A,class B,class Op>
110{
112 inline static
114 {
115 return op(a.reference(), b.reference());
116 }
117};
118
119template<class A,class B,class Op>
120struct Combine2<Reference<A>, B, Op, OpCombine>
121{
123 inline static
125 {
126 return op(a.reference(), b);
127 }
128};
129
130template<class A,class B,class Op>
131struct Combine2<A, Reference<B>, Op, OpCombine>
132{
134 inline static
136 {
137 return op(a, b.reference());
138 }
139};
140
141
142template<class A,class B,class C,class Op>
143struct Combine3<Reference<A>, B, C, Op, OpCombine>
144{
146 inline static
148 {
149 return op(a.reference(), b, c);
150 }
151};
152
153template<class A,class B,class C,class Op>
154struct Combine3<A, Reference<B>, C, Op, OpCombine>
155{
157 inline static
159 {
160 return op(a, b.reference(), c);
161 }
162};
163
164template<class A,class B,class C,class Op>
165struct Combine3<A, B, Reference<C>, Op, OpCombine>
166{
168 inline static
170 {
171 return op(a, b, c.reference());
172 }
173};
174
175
176template<class A,class B,class C,class Op>
178{
180 inline static
182 {
183 return op(a.reference(), b.reference(), c);
184 }
185};
186
187template<class A,class B,class C,class Op>
189{
191 inline static
193 {
194 return op(a, b.reference(), c.reference());
195 }
196};
197
198template<class A,class B,class C,class Op>
200{
202 inline static
204 {
205 return op(a.reference(), b, c.reference());
206 }
207};
208
209template<class A,class B,class C,class Op>
211{
213 inline static
215 {
216 return op(a.reference(), b.reference(), c.reference());
217 }
218};
219
220} // namespace QDP
221
222#endif
Expression class for QDP.
Definition qdp_qdpexpr.h:16
QDPExpr(const T &expr)
Construct from an expression.
Definition qdp_qdpexpr.h:28
T Subtype_t
Type of the first argument.
Definition qdp_qdpexpr.h:19
C Container_t
Type of the container class.
Definition qdp_qdpexpr.h:25
const Expression_t & expression() const
Accessor that returns the expression.
Definition qdp_qdpexpr.h:32
T Expression_t
Type of the expression.
Definition qdp_qdpexpr.h:22
OLattice< PScalar< PColorMatrix< RComplexFloat, 3 > > > C
Yet another random number generator.
Promote< T1, T2 >::Type_t Type_t
Definition qdp.h:377
static Type_t combine(Reference< A > a, Op op, OpCombine)
static Type_t combine(A a, Reference< B > b, Op op, OpCombine)
BinaryReturn< A, B, Op >::Type_t Type_t
static Type_t combine(Reference< A > a, B b, Op op, OpCombine)
BinaryReturn< A, B, Op >::Type_t Type_t
static Type_t combine(Reference< A > a, Reference< B > b, Op op, OpCombine)
TrinaryReturn< A, B, C, Op >::Type_t Type_t
static Type_t combine(A a, B b, Reference< C > c, Op op, OpCombine)
TrinaryReturn< A, B, C, Op >::Type_t Type_t
static Type_t combine(A a, Reference< B > b, C c, Op op, OpCombine)
static Type_t combine(A a, Reference< B > b, Reference< C > c, Op op, OpCombine)
static Type_t combine(Reference< A > a, B b, C c, Op op, OpCombine)
TrinaryReturn< A, B, C, Op >::Type_t Type_t
static Type_t combine(Reference< A > a, B b, Reference< C > c, Op op, OpCombine)
static Type_t combine(Reference< A > a, Reference< B > b, C c, Op op, OpCombine)
static Type_t combine(Reference< A > a, Reference< B > b, Reference< C > c, Op op, OpCombine)
static const Leaf_t & make(const Input_t &a)
Definition qdp_qdpexpr.h:76
Input_t::Expression_t Leaf_t
Definition qdp_qdpexpr.h:73
static Type_t apply(const QDPExpr< T, DTag > &expr, const FTag &f, const CTag &c)
Definition qdp_qdpexpr.h:88
ForEach< T, FTag, CTag >::Type_t Type_t
Definition qdp_qdpexpr.h:86
static Type_t apply(const Expr &expr, const FTag &f, const CTag &)
Definition qdp.h:80
LeafFunctor< Expr, FTag >::Type_t Type_t
Definition qdp.h:78
static Expression_t make(const T &a)
Definition qdp_qdpexpr.h:66
QDPExpr< T, C > Expression_t
Definition qdp_qdpexpr.h:64
const T & reference() const
Definition qdp.h:82
BinaryReturn< T2, T3, Op >::Type_t Type_t
Definition qdp.h:400