Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-06-04 13:18:36

Joel FALCOU wrote:
>> Yes, in proto v4 contexts are not necessary. They can, in some
>> circumstances, be easier to work with then transforms, so I don't plan
>> to remove them. They may even be better at compile time.
> Make sense indeed. It may solve my other problem then.
> I need to perform SIMD computation onto my matrix element. For scalar,
> proto provided the appropriate overload for let's say +,-,*,/ and so on.
> I think hat using visitor may solve the problem of selecing the proper
> form of operation on the fly.

I'm not sure how the data parameter figures here. Wouldn't the semantic
action be conditioned on the expression type? E.g., when an expression
is a binary +, do the binary + action. For that, you'd just use a proto
grammar decorated with transforms, and not involve the data parameter at

>> There are non-trivial changes, yes. Most significantly, the protocol for
>> implementing custom transforms has changed. Also, a bunch of functions
>> and types have been renamed as a result of review feedback.
> So, I better change now and adapt my code ?

Better IMO to wait until v4 is finished and committed to trunk.

> How can the v4 be downloaded ?

It's in boost's subversion repository under the branches/proto/v4 directory.

>> Not sure what you mean. Can you give an example?
> I had the impression that terminal helds value by reference until
> it get transformed and turne dinto value.

You can certainly write a transform that turns terminal references into
values, but that's not the default behavior.

Consider the following program that promotes int terminal to longs and
leaves all others as-is:

     #include <cstdio>
     #include <boost/proto/proto.hpp>
     namespace proto = boost::proto;
     using proto::_;

     struct Promote
       : proto::or_<
               , proto::terminal<long>::type(proto::_value)
           , proto::terminal<_>
           , proto::nary_expr<_, proto::vararg<Promote> >

     int main()
         int i = 0;
         proto::terminal<int &>::type _i = {i};
         std::printf("%s\n", typeid(Promote()(_i + 3.14)).name());

On MSVC-8, it prints:

struct boost::proto::exprns_::expr< struct boost::proto::tag::plus,
struct boost::proto::argsns_::list2< struct boost::proto::exprns_::expr<
struct boost::proto::tag::terminal, struct
boost::proto::argsns_::term<long>,0>, struct
boost::proto::exprns_::expr< struct boost::proto::tag::terminal, struct
boost::proto::argsns_::term<double const &>,0> const &>,2>

Note that the long is held by value (because that's what I specified),
and the double is still held by reference (because I didn't associate
any transform with double terminals).

>> Absolutely. A proto transform *IS* a semantic action.
> Ok then, the arguments are clear now :)

Eric Niebler
BoostPro Computing

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at