
Ublas : 
Subject: [ublas] What is the need of scalar expression templates?
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 20100718 14:13:05
Hi,
Looking at norm_* operations I've realized that they are implemented
as scalar expression templates.
My question is: why?
For instance, instead of having:
 [code] 
template<class E>
BOOST_UBLAS_INLINE
typename matrix_scalar_unary_traits<E, matrix_norm_1<E> >::result_type
norm_1 (const matrix_expression<E> &e) {
typedef typename matrix_scalar_unary_traits<E,
matrix_norm_1<E> >::expression_type expression_type;
return expression_type (e ());
}
 [/code] 
why not simply having (possibly introducing some logic for
differentiating between different kind of matrices  dense,
sparse...):
 [code] 
template<class E>
BOOST_UBLAS_INLINE
typename matrix_traits<E>::value_type norm_1 (const
matrix_expression<E> &e) {
// Code that computes the matrix norm 1
value_type norm;
for (...) {...}
return norm;
}
 [/code] 
I'm trying to figure out a real example where the solution with
expression templates is better, but I cannot find it.
Note, this is not a critic to the code.
I'm developing some containertoscalar functions (max,sum,...) and
since I'm not actually using expression templates I would like to know
what is the right way.
Thank you very much for the help!
Best,
 Marco