Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-10-16 03:52:41


On Friday 13 October 2006 16:02, Nico Galoppo wrote:
> Gunter Winkler wrote:
> BTW, if I understand the concept of expression templates, I assume that
> this will not construct a negated temporary of b. Is that correct?

Yes. (-b) returns the vector expression that negates each element of b at the
time of access.

> Why do the return types have to be vectors/matrices in most cases? Isn't
> that potentially expensive (many data copies) ? Is it a bad thing to try to
> write functions that return vector/matrix expressions?

I prefer to return matrices/vectors (or references of them) because the
construction of the correct type of matrix/vector expressions is quite
complicated. (Actually I have the compiler to compute it: First I set the
return type to int and second I copy the correct type from the "cannot
convert <very long type> to int" error message).

> Why is this necessary? vector_range is a model of vector_expression, so why
> wouldn't the first example work?

It is not necessary. The first also works with ranges, but the latter gives
the possibility of more specializations. I use this if I want to compute a
few lines of a large expression. (So I avoided to many project(..))

mfg
Gunter