Boost logo

Boost :

From: Cédric Venet (cedric.venet_at_[hidden])
Date: 2008-03-10 17:10:49


I decided to try to write a small vector library with proto to test it.

The following worked without problem (I will use extend further on but at
the moment the as_expr are needed)

  proto::display_expr( proto::as_expr(x)+proto::as_expr(y)*proto::as_expr(z)
, std::cout );

I then added

struct fastvec_reduction_tag {};
struct sum_ {};
template<typename A>
typename proto::result_of::make_expr<
// , MixedDomain
  , sum_ const
  , A const &
>::type sum(A const &a) {
    return proto::make_expr<fastvec_reduction_tag/*, MixedDomain*/>(sum_(),

Which work well

  proto::display_expr( sum(x) , std::cout );

And now, I would like to create a "function" dot(x,y) which expand to
I tried:

template<typename A, typename B>
typename proto::result_of::make_expr<
// , MixedDomain
  , sum_ const
  , BOOST_TYPEOF(boost::ref(proto::as_expr(A())*proto::as_expr(B())))
> const &
>::type dot(A const &a, B const &b) {
    return proto::make_expr<fastvec_reduction_tag/*, MixedDomain*/>(sum_(),

Which compile but fail at runtime when I do

  proto::display_expr( dot(x,y) , std::cout );

(it call << on an invalid vector (type of x and y)).

Is there a ways to create the tree for sum(x*y) directly or should I use a
transform (create a tree with a dot tag and then transform it with proto)?

The page 'users_guide\expression_construction\construction_utils.html' seems
very complete, but hard to understand how to put it in practice, perhaps you
could link it to some use in the example.



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