
"Matthias Troyer" <troyer@itp.phys.ethz.ch> wrote <...>
The above creates a lot of temporaries of course.
Why? Using expression templates there will be absolutely no temporaries.
In my experiments with E.T, I found that it only became advantageous when use with (say) a vector of more than 4 elements. Before that it seemed to create more temporaries than eager evaluation. I seem to remember someone else backing this up somewhere too. The other problem with E.T. is that it affects the way you write expressions, as you sometimes need to force the evaluation: template <typename T> void f(T t) { std::complex<T> value(t,t); value * t; } double a,b ; f ( a * b); // OK f ( ET_expression(a , times, b)); // Error No operator * (std::complex<some_ET_expr> , <some_ET_expr>) IOW E.T. performance isnt free... regards Andy Little