From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2005-03-08 07:26:45
Pavel Chikulaev wrote:
> "Tobias Schwinger" <tschwinger_at_[hidden]> wrote in message
>>- Custom per element operations
> You mean
> matrix<double> m;
> double d = transpose(m); //
> don't you?
> It's not yet supported, but I think I can do it.
That's the special case where all elements are used.
I use 'apply', 'apply_one' and 'apply_but' functions that allow me to
apply functors to all elements, one element and all but one elements,
respectively (I use different versions for both static and dynamic
indices and both static and dynamic functors):
// Create an expression inverting the first element
// of my_vector (using Boost.Lambda)
apply_one<0> (my_vector, - _1)
Further the result type may not always be the same as the argument type:
vector_slice<0,3> (my_quaternion) = direction * std::sin(a*half);
>>The design should allow to optionally replace operations to make use of
> Library also supports it. AFAIK It's template specialization of lazy
> operator, isn't it?
It can be difficult to add such specializations - depending on how your
expression templates are implemented. It's just something to keep in mind.
And while we're at it, and because it seems you found the previous post
inspiring, here is some more:
- There should be an implicit conversion sequence that allows to
evaluate a lazy expression:
( Guess you thought of this one - mentioning it just in case )
xpd(direction * std::sin(a*half), vector_slice<0,3>(my_quaternion))
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).
- Do you know the Boost.Assign technique ?
I use a similar approach to have a nice syntax for initialization and
inlining that works within expressions:
my_quaternion = n_x * sin_half_a
, n_y * sin_half_a
, n_z * sin_half_a
= (vec_inl| n_x,n_y,0.0) * sin_half_a;
( The 'my_quaternion' variable from the examples is a four-dimensional
vector, _not_ a boost::quaternion. )
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk