Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Forwarding evaluation via tag
From: Eric Niebler (eric_at_[hidden])
Date: 2009-09-30 09:46:00


Joel Falcou wrote:
> Samll question, for a given eval_xpr, if I do :
>
> eval_xpr()(x+y, state, data);
>
> it seems that the operator()(Expr,State,Data) of the transform
> require the Expr to be a reference and so, the former call fails as x+y
> is a temporary. Is it on, purpose or is it a missing feature ?

eval_xpr gets an operator() overload defined by proto::transform that
looks like this:

     template<typename Expr, typename State, typename Data>
     ....
     operator ()(Expr &e, State &s, Data &d) const
----------------^^^^^^^

You are observing that the "Expr &e" is a non-const ref, and ordinary
rvalues do not bind to it. But the rvalues that Proto generates are all
const-qualified, which *do* bind to this reference. Notice that I used
"eval_xpr()(x + y)" in the example I sent around yesterday, and it works
there.

So the question is: why doesn't this work for you? Have you defined your
own operator+ overload? Could you send your code around again?

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net