By the expression templates technique, a matrix expression like
D = A*B+sin(C)+3.;
is pretty much equivalent, in terms of computing perform
In c++11 you can use auto
auto D = A*B+sin(C)+3.;
assuming you are using expression templates, the type of D would be
.
Now, you have to use this carefully, because you are saving up some memory (no need to allocate space for a matrix) but depending on how you use it this may not be the best.
Think about
F = D*E
An element D[i][j] needs to be "visited" many times when computing D*E (actually n times where n is the size of the matrices). If D is a plain-matrix type this is no problem. If D is an expression you are evaluating it many, many times.
On the contray, doing
F = D + E
is fine.
Think about this: you can not write F = E*(A*B+sin(C)+3.);
using only two nested loops.