
troy d. straszheim wrote:
Eric Niebler wrote:
Using expression templates to eliminate unnecessary temporaries is a well understood idiom; it's why expression templates were invented in the first place. You don't need rvalue references at all.
Could you say more about what you are trying to do and why you think rvalue references are needed?
Maybe I've missed something stupid or have organized things so as to cause myself trouble. In an expression like
// these contain pointers to memory out on the GPU array<float> A, B(10,10), C(10,10);
A = exp(B) * C;
When it is time to evaluate the expression, the grammar fires the transform for exp(B) first. It creates a temporary T with the same dimensions as B and and a function is called to compute the result into T. Now 'T * C' happens. In this case there is an available temporary, 'T', so the result can go right in to T. T is returned and moved in to A. Done... at least, that's the idea.
This is how the expression would be evaluated eagerly -- that is, in the absence of expression templates -- right?
So how should these transforms know whether their arguments are overwritable or not? I didn't see how to get the 'slicing through the expression' approach, as in the calc examples, with contexts and overloaded operator[], to work here: each step of the calculation has to get done all at once, via a function call. But maybe it is time to go back and look again.
You use expression templates when you can take advantage of domain-specific knowledge combined with a complete description of the expression tree you're trying to evaluate to perform domain-specific optimizations like loop unrolling. You need to ask yourself, "What special features of my domain abstraction can I use to optimize the evaluation of this expression?" If the answer is "rvalues," then that's not an answer that justifies the use of expression templates. If you can find a way to use the full expression to precompute the size of the result and compute it in-place, *now* you're talking. See? -- Eric Niebler BoostPro Computing http://www.boostpro.com