Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2005-03-09 08:31:31

Pavel Chikulaev wrote:
> "Pavel Chikulaev" <pavel.chikulaev_at_[hidden]> wrote in message
> news:d0k7sp$au4$
>>>It's nice when the cross product implementation can indicate by the
>>>paramter type of its signature that it needs an intermediate result
>>>(otherwise it would have to evalutate the expression explicitly or
>>>direction * std::sin(a*half) will be evaluated twice).
>>It won't be evaluated twice, AFAIK.
> One more oops.
> It will be in only one rare case:
> xpd(LAZY_OP_RESULT_OF(your_vector));
> //anything lazy-convertible to vector.
> //will not be evaluated before calling xpd
> But in most cases you should write:
> xpd(const your_vector &);
> //Lazy expression will be evaluated before
> //calling xpd

I guess I have to apologize for being quite unclear here. Sorry !

It becomes problematic if our_vector is a template ( <N,ScalarT> for
example - btw. the cross product may be a bad example since it only
applies to N == 3 ), because there is no way for this to work if the
arguments are expression objects (because you can't have both deduction
and user defined conversion at once).

The possible ways around it are:

a) The library provides the user with a way to deduce the "conceptual
type" from expression objects, or
b) friend name injection is used from inside the vector class so
our_vector is a full specialization (== a type) and not a template anymore.

The preferred solution is clearly point a, because it does not require
the vector class to know all function that want to take a vector (==
already evaluated expression in this context) as parameter.

> Also have lazy::evaluate( ) function to evaluate lazy-expression whenever
> you want.

Well, that was quite easy to guess ;-).



Boost list run by bdawes at, gregod at, cpdaniel at, john at